I don't know Docker, where to start?

Milhomem
3 min readSep 11, 2021
Photo By Isa Zapata, Food Styling By Pearl Jones

Run one thing per container

Don't use Supervisor inside a container! Docker principle is to have one single process per container and adopt composition. Think of a container as a single binary that will always do the same thing. The intent is to make things modular and we should try our best do to that, but that is still super hard.

You don't need Supervisor anymore if you have proper containers. Docker will take the responsibility of monitor and restart all containers when needed.

Don't create your first Dockerfile

Yes, don't start there. Things can get very complex when you start writing your own Dockerfile. Opt-in for using a Docker hub image or an official image instead.

Creating your own image is an advanced feature of Docker and hard to use properly, let it be for when you are more familiar with how Docker works.

Hub is where you are going to get base images from the most famous open-source projects, all ready-ish for you to use.

Later, when you have to create your own images, you can also push and host them on the Docker hub for free.

Start with Docker Compose

It's easier to understand a simple compose Yaml file rather than trying to understand the underlying Docker CLI syntax. Start with docker composer and a few docker command line commands to get used to things.

See this simple LAMP example. Download the following files in a folder:

Now run, from inside the folder:

MYSQL_ROOT_PASSWORD=test \
docker compose up

Open your browser on http://localhost:8080 and you will have your 3 containers connected and talking to each other.

Once you are done, hit ctrl + c to stop all containers. If you want to keep it running for longer, in the background, append --detach to the docker command.

Always use the same image for dev and prod

Making sure dependencies are met across all environments is what Docker is trying to solve. If you manage to use the same image in dev and prod, you will not only make it easier to deploy but it will be consistent after testing and QA.

Avoid installing dependencies on your local computer. Execute things on containers instead.

But how to create containers that can handle the differences from environments? That is the composition challenge!

What to do next?

  • Create your own Dockerfile
  • Publish your first image to Docker Hub or to a private repository
  • Learn how to use Environment variables to deploy the same image in different environments

--

--

Milhomem

Engenheiro viciado em colocar ideias em prática e fazer códigos alcançarem a realidade