-
Notifications
You must be signed in to change notification settings - Fork 3
Docker
- What is docker?
- Why use docker?
- Why not use docker?
- Creating a Docker Image
- Building the Image
- Creating the Container
- Useful Links
Docker makes running software applications on any system easy. Docker uses containers to wrap software applications so that they can be run with the docker engine on any system.
You can think of the docker engine like a mini-VM, but instead of having all of the overhead of a traditional VM, docker containers run on the host operating system.
Docker containers can have their own filesystem and you can incorporate all of the dependencies for a software application inside of a container so that it is easily portable.
Docker should be used for software applications that can be encapsulated in a container.
Not everything is compatible with docker.
You can't run a linux container on a windows machine.
Docker containers are less isolated than VMs, so a virus in a container can affect the host operating system.
Creating an image requires a Dockerfile
which is just a text file containing the steps that would be performed in a command line to set up the environment needed to run the application. Below are example commands to include
FROM
- sets the base image to use (FROM java:8
uses the image for Java8)
RUN
- can be used to run a command or an executable with parameters
CMD
- similar to RUN
but specifies defaults (can only have 1 in Dockerfile)
EXPOSE
- the port the container is listening to at runtime
ADD
- copies files from the source (host) to the destination (container)
For more commands and further information see additional Dockerfile commands
To build the Docker image run docker build -t <image-name> .
from the directory the Dockerfile
is located.
The -t
option tags the image with a name to be used in later steps.
Additionally, the path to the Dockerfile can be provided as a second parameter instead of the .
or a URL can be provided to pull an image from another location like GitHub.
Once the image has been built, the container can be created via
docker run <image-name>
-d
is a flag that can be included before the image name to run the container in the background.
-p
can be used to map a host port to the port the Docker container is listening to.
-p 4567:4567
means that the service listening at the container's port 4567
can be accessed via localhost:4567
-p 8080:4567
means that the service listening at the container's port 4567
can be accessed via localhost:8080
https://docs.google.com/document/d/1cU_XRdakQ7lMFiPlaKCfAZaXwfxUGMX243xHiXMyiL8/edit