Docker containers are used to run applications in closed containers.
The Dockerfile describes the environment prerequisites for the specific application.
The Dockerfile can then be used to create an image. This image can then be executed in a container(s).
- Go to Docker and download the necessary installation file.
- Windows 10: during the installation you will be prompted to install the Windows Subsystem for Linux (WSL) as well. Follow the instructions during the installation process.
After installation of Docker you can use the tutorial as part of the installation process to get started.
# Pull in our OS
FROM alpine
# Install dependencies (in this case c++ compiler)
RUN apk add g++
# Set working directory
WORKDIR /example
# Copy example to container (into working directory)
COPY main.cpp .
# Compile the example
RUN g++ main.cpp -o example
# Command executed on startup of the container
# There may only be one CMD in a dockerfile
CMD ./exampleAfter the Dockerfile is created, one can create an image with the following command:
# docker build -t <image_name> <folder with Dockerfile>
docker build -t example .After an image has been built, start a container, based on an image:
# docker run --name <name of container> -t <name of docker image>
docker run --name example_container -t exampleIf the container has been created and you want to restart the container use:
# Use -i to attach stdin to the terminal
# docker start -i <name of container>
docker start -i example-container