Docker is a platform for development and deployment with containers. Containers provide similar isolation to virtual machines but use less computing power by leveraging the host kernel. Docker enables standardized packaging. Applications become portable as they are abstracted from the environment in which they are run.
Information on this page is taken from Docker's getting started guide.
An image is an executable package that includes everything needed to run an application - the code, a runtime, libraries, environment variables, and configuration files. A container is a runtime instance of an image - what the image becomes in memory when executed (a process).
Run a Docker image with
docker run <image>. The
-p argument is often used
to map a machine's port to a container's published port. Specify
-d to run
the container in the background with detached mode.
List all running containers with
docker ps, include
--all to also show
docker stop <container> to stop the container. You may also
rm containers. Lastly, run
docker container prune to remove all stopped
Dockerfile is a plain text file that contains a list of commands to create
a Docker image. An example appears below. Build the Docker image with
build .. The
-t (tag) argument is often used to name the image.
# Define a parent image. FROM python:3.6-slim # Set the working directory. WORKDIR /app # Copy to the container. COPY . /app # Execute commands. RUN pip install -r requirements.txt # Make ports available externally to the container. EXPOSE 80 # Define environment variables. ENV NAME World # Run commands on launch. CMD ["python", "app.py"]
A registry is a collection of repositories, and a repository is a collection
of images. Run
docker pull <image> to fetch an image from a registry. See
all downloaded images with
docker images. Official images are maintained
and supported by Docker. They are typically one word long. User images build
on base images are usually formatted as
docker build will build and place an image on your machine's local
registry. Publish images to an external registry by logging in (
login) and running
docker push <image>. Images can be tagged with
tag <image> <name>. Associate a local image with a repository on a registry
with the notation
username/repository:tag. For example,
docker tag example