Languages
[Edit]
EN

docker and docker-compose - list of most useful commands

4 points
Created by:
Marcin
16180

Hi, today I'd like to share with you list of most useful docker and docker-compose commands.

I find it very useful to have this kind of cheat sheet / shortcuts.

docker list most useful commands

# list all images
$ docker images -a

# remove all images
$ docker system prune -a

# kill container
$ docker kill put_container_id_here
# eg:
$ docker kill 4f2135f4f315

# list all containers
$ docker ps

# build current project where we have Dockerfile
$ docker build .

Remove more then 1 docker image in single line:

# list all docker images
$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
mysql                    latest              e1d7dc9731da        2 weeks ago         544MB
docker/getting-started   latest              1f32459ef038        2 months ago        26.8MB
openjdk                  8-jdk-alpine        a3562aa0b991        16 months ago       105MB
# remove 2 images in single line
$ docker rmi e1d7dc9731da && docker rmi 1f32459ef038

docker-compose list most useful commands

# start based on docker-compose.yml in current directory
$ docker-compose up

$ docker-compose stop
$ docker-compose down

$ docker-compose ps

# print docker-compose with .env imported
$ docker-compose config

# show last 10 lines of logs from each docker container
$ docker-compose logs -t -f --tail 10

Other useful commands

# restart docker service
service docker restart

Build java project with mvn + skip unit tests

mvn clean install -Dmaven.test.skip=true

References

Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join