docker build .
- Only run a image
docker run [image_name]
- Run in a port
docker run -p [port]:[port] [image_name]
- Run with interactive command line
docker run -it [image_name]
docker images
- To no more about an image
docker image inspect [image_name]
- List of running containers
docker ps
- List of all containers
docker ps -a
- Start a container
docker start [container_name]
- Start and attached a container
docker start -a [container_name]
- Stop a container
docker stop [container_name]
- Attach a container
docker attach [container_name]
- Detach a container
-d
means detched
docker run -p [local_port]:[server_port] -d [container_name]
- Detach a container and remove automatically after stop the container
docker run -p [port]:[port] -d --rm [container_name]
- Show the previous log of a container
docker logs [container_name]
- Show current and running logs
docker logs -f [container_name]
- Remove a single container
docker rm [container_name]
- Remove multiple by white space and put all container names.
docker rm [container_name1 container_name2 container_name3]
- Remove all stopped containers
docker container prune
- Remove a single image by
docker rmi [image_name]
- Remove multiple images by white space separator
docker rmi [image_name1 image_name2 image_name3]
- Remove all unused images by
docker image prune
- Copy to a container
docker cp [file_path] [container_name]:/[destination_path]
- Copy from a container
docker cp [container_name]:/[file_path] [destination_path]
- Add name to a container
docker run --name [desired_name] [container_name]
- Add name and tag to image
docker build -t [desired_image_name]:[desired_tag_name] .
- Rename a docker image
docker tag [old_image_name] [new_image_name]
- Push a docker image to docker hub
docker push [repo_name]
- Pull a docker image from docker hub
docker pull [repo_name]