Skip to content

Instantly share code, notes, and snippets.

@nasirhafeez
Last active August 3, 2021 09:57
Show Gist options
  • Save nasirhafeez/2d7baff65473cd873493d51d717e7523 to your computer and use it in GitHub Desktop.
Save nasirhafeez/2d7baff65473cd873493d51d717e7523 to your computer and use it in GitHub Desktop.
Docker Commands

Docker Commands

Installation

wget -qO- https://get.docker.com/ | sh

Commands

General

docker version
docker info
docker history <image_name>
docker inspect <image_name>

Images

docker image ls OR docker images
docker image rm aamirpinger/helloworld:latest
docker pull aamirpinger/helloworld:latest
docker tag <image_name> aamirpinger/<new_name> 	[copy image_name to aamirpinger/new_name]

View container status

docker container ls OR docker ps
docker container ls -a OR docker ps -a

Running containers from images

docker run -it aamirpinger/helloworld sh	 [interactive mode]
docker run -d aamirpinger/helloworld		 [detached mode]
(exit command to exit from container; Ctrl + PQ to keep container running and return to host machine's shell)
docker exec -it <container_ID or name> sh

Start/stop/delete container

docker container stop <container_ID or name>
docker container start <container_ID or name>
docker container rm <container_ID or name>

Publishing Port

docker container run -d -p 5010:80 aamirpinger/helloworld
docker container run -d --name <custom_name> -p 5010:80 aamirpinger/helloworld

Building images

docker build -t <image_name> .

Pushing Images

docker login
docker push aamirpinger/node-tag-image:latest

Bind Mount

docker run -it -v </complete/path/on/host>:</path/inside/container> aamirpinger/helloworld sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment