Docker Basics
Download Docker image
If you don't specify version, docker downloads the latest.
docker pull imageName:imageVersion
List all Docker images
docker images
Create and run Docker container
docker run -it imageId /bin/bash
or docker run -it imageName /bin/bash
Publish or expose ports: -p externalPort:internalPort
Assign a container name: --name containerName
Auto start on boot: --restart=always
Tag a local image
docker tag imageID newImageName
Detach from Docker's process
exit
or Ctrl+D
(This method may stop the container's execution).
Ctrl+P+Q
(The container is still executing.).
List all containers
docker ps -a
Start a container
docker start containerId
or docker start containerName
Stop a container
docker stop containerId
or docker stop containerName
Attach to a running container
docker attach containerId
or docker attach containerName
The best way: docker exec -it containerId /bin/bash
or docker exec -it containerName /bin/bash
Rename a container
docker rename containerName newName
Follow log output
docker log -f containerId
or docker log -f containerName
Remove Docker container
docker rm containerId
or docker rm containerName
Remove Docker image
docker rmi imageId
or docker rmi imageName
Force remove: docker rmi -f imageId
Commit a container
docker commit containerId newImageName
The commit operation will not include any data contained in volumes mounted inside the container.
Create a docker image backup
docker save imageName > filename.tar
Load a docker image backup from a file
docker load < filename.tar