Skip to content

mjuyelrana/docker-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Commands

1. Build command

  docker build .

2. Run command:

  • 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]

3. List of images:

docker images
  • To no more about an image
docker image inspect [image_name]

3. List of containers:

  • List of running containers
docker ps
  • List of all containers
docker ps -a

5. Start/stop a container:

  • Start a container
docker start [container_name]
  • Start and attached a container
docker start -a [container_name]
  • Stop a container
docker stop [container_name]

6. Docker attach/detach to a container

  • 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]

7. Show the all docker logs

  • Show the previous log of a container
docker logs [container_name]
  • Show current and running logs
docker logs -f [container_name]

8. Remove containers:

  • 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

9. Remove Images:

  • 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

10. Copy from/to container

  • Copy to a container
docker cp [file_path] [container_name]:/[destination_path]
  • Copy from a container
docker cp [container_name]:/[file_path] [destination_path]

11. Naming and Tagging of container and image

  • 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]

12. Push and pull docker image to docker hub

  • Push a docker image to docker hub
docker push [repo_name]
  • Pull a docker image from docker hub
docker pull [repo_name]

About

Simple express app for learning docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published