Skip to Content
πŸ“ NotesπŸ’» DeploymentDocker1) Get Started

Basic Docker usage and command

Download the git from: https://www.docker.com/Β 

Commands

- Get image

docker pull <images_name>

- Build

docker build -t <tag_name> . docker build -t docker-example .

- Run

Care hostPort:containerPort => map_to_target_port:my_current_port

  • <Port-to-outside>:<Inside-port>

For example, you got a express.js port to 8080, and you want your user to access with http://xx.xx.xx.xx:32145, you have to set:

  • 32145:8080
docker run -d -it -p 8080:8080 <tag_name> docker run -d -it --restart=always -p 8080:8080 docker-example
  • -d : --detach Run in background.
  • -it : --interactive + --tty Make your container get your stdin and get nice formatted output from container.
  • -p: --port Using which pair of ports.
  • --restart=always: Always restart on exit.

- Docker Compose

docker-compose up # pull the images that the `docker-compose` will use docker-compose pull # Run in background docker-compose up -d docker-compose stop docker-compose rm -rf <name> # Delete

- List container

docker ps docker ps -a # With hidden / stopped container # Stop container docker stop <CONTAINER_ID / IMAGE_NAME> # Remove container docker rm <CONTAINER_ID / IMAGE_NAME> docker logs <CONTAINER_ID / IMAGE_NAME> docker logs 841851bc7e31

- List images

# ls images docker images # Remove container docker image rm <IMAGE_NAME>

- Go inside the images

docker exec -it <CONTAINER_ID / IMAGE_NAME> bash

- Volumes

# Vol mount docker -v <Your_path>:<docker_internal_path> # e.g. Mount in linus docker -v /var/run/docker.sock:/var/run/docker.sock # e.g. Mount Local Folder In windows docker -v C:/myFolder/data:/data # e.g. Mount Local Folder In linus docker -v ./data:/data
Last updated on