Skip to content

Instantly share code, notes, and snippets.

@DavidSabine
Last active October 26, 2022 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidSabine/6f21f4b3456703f2a886fc6ede50af40 to your computer and use it in GitHub Desktop.
Save DavidSabine/6f21f4b3456703f2a886fc6ede50af40 to your computer and use it in GitHub Desktop.
How to make the world's most basic Docker container.

Pre-requisites: Ensure Docker is Installed & Working

It’s important you have Docker Engine and Docker CLI and Docker Compose. How to know if you have these on your system?

Note: Docker Desktop for Linux/Mac/Windows includes all the necessary tools.

You’ll know whether these tools are installed and working if, at any command prompt, the following commands will report the version number of each tool.

docker --version

My system responds with:
> Docker version 20.10.17, build 100c701
docker-compose --version

My system responds with:
>Docker Compose version v2.10.2

Let’s make some containers from an existing image, then remove them from our system.

It’s helpful to know a few basics to keep your environment clean. (The following steps are explained in great detail in this geekflare article starting at the point they create a “Docker Hello World Container”.)

  1. docker pull hello-world: Build a simple image in a docker container and run a “Hello World” application.
  2. docker images: List all your images. You’ll see a new image, called hello-world is added to your local collection.
  3. docker run hello-world: Run the app within the container.
  4. docker container ls -a: List all docker containers.

It’s important to know that a new container is produced every time you run the app. For example:

  1. Run #3 above, again.
  2. Then run #4 above, again, and notice a new container in the list.

(To prevent the creation of a new container every time you want to interact with the app, there are ways to execute commands in a running container, et cetera. Those techniques are not described here.)

It's important to know how to clean up your environment.

(These commands and more are described in the “Complete Guide for Removing Docker Images” by Abhishek Prakash.)

  1. docker container ls -a: List all your containers. (Note the names or container ids.)
  2. docker rm boring_hoover: Remove a container with name “boring_hoover”.
  3. docker image rm hello-world: This will remove the hello-world image created in #1 above. Note this will fail if any containers exist using that image. (So remove those images first.)

Takeaways

  • Using docker, you downloaded an image, created containers from that image, and ran a program on that image.
  • Then you cleaned up the Docker artifacts on your system: the containers and the new image.

See also

My next article demonstrates how to do all this with docker-compose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment