Last active
May 27, 2022 19:21
-
-
Save musleh0001/fcd72febecf3fb2ea702a015d404e99b to your computer and use it in GitHub Desktop.
Basic Docker Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker --version [list docker version] | |
docker run hello-world | |
docker container ls | |
docker container ls -a | |
docker contianer rm -f $(docker container ls -aq) [remove all container] | |
docker image ls | |
docker images | |
docker image rm <image-name> [remove docker image] | |
# Postgresql | |
docker run --name postgresql -e POSTGRES_USER=myusername -e POSTGRES_PASSWORD=mypassword -p 5432:5432 -v /data:/var/lib/postgresql/data -d postgres | |
# Copy file to docker container | |
docker cp foo.txt container_id:/foo.txt | |
docker ps --> list running container | |
docker run -d nginx --> -d run in the background | |
-p external_port:internal_port | |
docker run -p 8080:80 -d nginx --> -p ports | |
docker run -p 8080:80 -p 3000:80 -d nginx --> expose multiple port | |
docker run --name website -p 8080:80 -p 3000:80 -d nginx --> give container name | |
# Format output | |
export FORMAT="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n" | |
docker ps --format=$FORMAT | |
# Volumes | |
Note: Allows sharing of data, Files & Folders. Between Host and Container or between containers | |
docker run --name website $(pwd):/usr/share/nginx/html:ro -p 8080:80 -d nginx:latest | |
docker run --name website /home/musleh/Desktop/website:/usr/share/nginx/html:ro -p 8080:80 -d nginx:latest | |
docker run --name website-copy --volumes-from website -p 8080:80 -d nginx:latest --> use another site volume | |
docker exec -it [container_name || container_id] bash --> go inside container |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
initial commit