5 Docker tricks make your life easier – Part 1

1. Logs and monitoring

You can view logs of a container by

And you can monitor output from a container by

2. Open a shell in the container

If you want to quickly dive into the container, and see what’s inside a particular file, you can do so by:

However, the container must be already running, if the container failed to start, you have to find another way, e.g.  overriding the entry point of the container.

3. Find out useless (not referenced) images

After trying lots of times perfecting a Docker build, you may run into a problem which there are many garbage images.

Output the list of images that is not used by any created containers. (“dangling” as in “dangling pointers”, if you know C)

Just output the image IDs

4. Remove all useless images

5. Use docker-compose

With Docker compose, you can deploy one or more container simply by  docker-compose up -d , and undeploy by  docker-compose down .

Docker compose can be regard as a way to specify container config in a config file, but it also do more than that, it helps you to link 2 or more containers together nicely (“orchestration”).

Example docker-compose.yaml

What Docker does is it automatically add the IP of “mariadb” to the “hosts” file of “app”, so you can reference the database by “db”.

More tips and tricks later!

Share your thoughts