Sitemap
Christopher Tucker

Christopher Tucker

Docker

2 min readJul 14, 2020

Over the last week I’ve delved into the wonders of Docker and I would like to share the little knowledge that I have learned so far.

Docker is an engine for creating “containers”. Containers are not exactly virtual machines, but you can think of them as a type of virtual machine that is easily accessed and completely expendable. Containers run programs in virtual isolation from the machine they are running on, with their own operating system (linux), environment variables, and packages. Pre-built “docker images” can be easily pulled down from docker hub and running in minutes. Custom images can be built and published to docker hub, available to pull down at anytime with full confidence that they will run out of the box.

There are some huge advantages to using docker containers. Isolated environments mean there will be no clash between different programs running. For example, almost all deployed applications run on linux servers, but may be developed on mac or windows, creating possible file system conflicts or other incompatibilities. Installing a program on your own machine may create environment clashes with other programs, docker solves this issue. All dependence are saved inside the container. Easy to pull down new docker image from docker hub and try again if it’s not set up correctly. Container images can be built and destroyed at will, and“layers” can be added to containers for increased customization.

Getting started is as easy as installing docker on your machine, and doing a docker run (sudo permissions needed) on a container that you find on hub.docker.com. Installing on linux, mac, and windows may take different commands, but they are relatively simple.

Get Christopher Tucker’s stories in your inbox

Join Medium for free to get updates from this writer.

When you do a docker run, you configure your container with runtime properties on the command line. Here are a few of the basics that I came across:

  • — name [container name] | What you want to name your container.
  • — network [network name] | Includes container in a network of other containers so they can communicate with each other.
  • -d | Runs container as a daemon process (runs in background without needing a shell).
  • -p [local port] : [container port] | Maps connections from a local port to a container port. Used to expose services in the container to outside processes.
  • -v [local directory] : [container directory] | Maps the directory to save data to on the host machine, from the directory within the container.
  • — restart unless-stopped | Causes the container to start when the host computer starts.

Once your docker container is up and running, there are a few helpful command line arguments that will help you navigate your containers:

  • docker ps | Shows all running docker containers.
  • docker container ls -a | Shows all containers regardless of status.
  • docker inspect [container name] | Shows all information about container including status, ports exposed, etc.
  • docker kill [container name] | Stops container from running, but it remains on your system, ready to be started again.
  • docker rm -f [container name] | Kills container, and removes it from your system.

Over all, docker is an extremely useful and popular tool and I look forward to using it regularly in future projects.

--

--