Create your first Docker container in 60 seconds

Suresh Sarda
2 min readSep 28, 2019

Prerequisites

  1. You have Docker installed (See instructions to install)
  2. (Optional) You know to to deploy a Flask application using command line

Docker works on basis of configurations. It’s a declarative way of telling Docker how to build images.

A typical workflow starts with a base image, works on top of it, saves it either for future use or gets reused as a base image of something else.

Creating Your First Image

Dockerfile

This file list down steps/configuration to build an image. In this example, we are trying to run a Flask application.

A bit of backstory on Flask applications

Typically, Flask applications have an entry point, server.py in this case. We can start the server by simply executing: python server.py, assuming that the current Python environment has all the dependencies installed. If not, we can install the dependencies from a requirements file.

Running the container

  1. To run the container, you first need to build it

This can be achieved like this:

sudo docker build --tag=gettingstarted .

2. Once built, make sure it is present in your local registry

sudo docker image ls

(More on this listing later, but you should see the container gettingstarted with latest tag here)

3. Now is the time to run the container

docker run -p 5000:5000 

This runs the Docker container by the given name. The -p parameter is the port mapping from the host OS to the container.

That’s it! You have created your first Docker container!

Originally published at https://sureshsarda.in on September 28, 2019.

--

--