Here is my own summary of common docker commands in need for day-to-day uses.
- See all docker images on the host
docker images
- Search for docker images on Docker Hub
docker search <image name>
Ex:
docker search gdal - Run a docker image (create a docker container instance) and attach to it
docker run -it <docker image name> [command]
Ex:
docker run -it centos bash
- Run a docker image in detach mode
docker run -d -it <docker image name> [command]
Ex:
docker run -d -it centos
- Exit from docker container and terminate the process
exit
- Exit from docker container WITHOUT terminating the process
Ctrl-P + Ctrl-Q
- Commit change made to docker container as a docker image
docker commit -m “<commit msg>” <container id/name> <image name>
Ex:
docker commit -m “Setup dssat run-time env” 8avc04mn nabito/centos-dssat
- Check running docker container
docker ps
- Check all run docker container (including exited and other status)
docker ps -a
- Stop a running docker container
docker stop <container> - (Re)Start a stopped (exited) docker container
docker start <container> - Login to an already running docker container (connect stdio with docker’s PID1 process)
docker attach <container id/name>
Ex:
docker attach 4sdjn9a3g
- Execute a command on a running docker container
docker exec -it <container id/name> <command>
Ex:
docker exec -it 4sdjn9a3g bash
- View log of a container
docker logs <container id/name>
Ex:
docker logs 4sdjn9a3g
- List docker volumes
docker volume ls