DEV Community

Rachael Tatman
Rachael Tatman

Posted on

The same five Docker commands I have to look up every dang time (and one I always try to use that never works)

I really don't know what it is about Docker (maybe that I need to mess with containers fairly infrequently, maybe that it's just different enough from git that I get confused between the two, absolutely that I don't remember which commands are for images and which are for containers) but for some reason I find myself looking up the same five commands every dang time.

This post is primarily for me, so that I can stop digging through the Docker docs, but I figured some other folks might have the same problem as well.

Looking at stuff

  • docker ps - lists running containers
  • docker image ls - lists images (not containers) in the local directory
  • docker logs [container_name] - the container name will be at the end of the line of output of docker ps (images don't have logs; they're like classes)

Creating & uploading a new image

  • docker build . -t username/image:tag - create a new image from a Dockerfile (in current directory) and context
  • docker commit - this commits a container, not an image, stop using it to try and commit images to Dockerhub Rachael it 100% does not work
  • docker push username/image:tag - pushes a built image to Dockerhub (you do not need to commit images, stop trying to commit images)

Bonus: Docker compose

  • docker-compose down - use this instead of docker-compose kill or when you restart the container it will still use the old image
  • docker-compose up -d - use this to get new containers set up (restart will just wake up your containers w. the same images), the detached flag keeps you from getting log spam

Top comments (2)

Collapse
 
alastairmeasures profile image
Alastair Measures

Thanks, I resonate with this; which is why I use docker-compose and portainer as far as possible. The need to focus on whatever I am developing (on top of docker) rather than docker itself, is my justification.

We have a 1968 Morris Minor (classic car) and whilst is great to have a tool kit in the boot/ trunk ... I do not want to be using it the whole darn time.

Collapse
 
amitgol profile image
Amit Goldstein

Compose is now part of docker, so you can simply do - docker compose down docker compose up etc