docker commands to make you more productive

If you found this article interesting consider sharing it!

Docker has quickly become a popular tool for developers and devops to develop, deploy and scale applications. In this post I want to show some docker commands that can help you increase your productivity with docker.

structure and more commands

container with blue sky

This article structures the commands in multiple subsections. The first one is about managing images and containers. How to map ports would be an example for it.

That section is followed by commands to attach to a container, either via shell or file- system.

Lastly there is a section for my readers working in an enterprise setup. This section mostly focuses on proxy configuration for docker.

For additional docker commands, you can always check the docs.

If these tips help you, consider subscribing to my newsletter.

docker commands to manage images && containers

Map port 8080 to 80 (-d is for detached mode)

docker run [-d] -p 8080:80 <imagename>

Remove all containers from this machine

docker rm $(docker ps -a -q)

Stop all running containers

docker stop $(docker ps -a -q)

docker commands to attach to containers

Enter into a running container with a new tty

docker exec -it <container-id> bash

Run an “endless” Ubuntu container (without endless loop, it will just exit/stop after echoing Hello World)

docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

Mount folder. Also possible with multiple folders

docker run -d -v /data/html:/var/www/html [-v folder2:location2, etc...] <imagename>

docker in an enterprise setup

Maybe this section will one day be expanded into an own article. But for now, here are some commands to use when working behind a proxy.

Set proxy in your dockerfile (add these lines at the beginning)

ENV http_proxy http://server:port
ENV https_proxy http://server:port

Building a container behind a proxy

docker build --build-arg http_proxy=http://server:port [...]

Configuring the docker client to use a proxy in ~/.docker/config.json

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://server:port",
     "httpsProxy": "http://server:port",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}

If you use those settings/ commands you should be good to go to work behind a proxy.

Conclusion

These commands are just the tip of the ice-berg don’t forget that you can always use docker --help or docker <command> --help to get additional help for docker or a specific command.

Let me know in the comments down below why you liked or disliked this post, and if I should make a more in-depth/ advanced post about docker commands or docker in general.


If you found this article interesting consider sharing it!
Advertisements