Docker Commands
Docker Commands:
Cheatsheet:
https://gist.github.com/bigslycat/23b738df23ec08063de18c3afeaf9038
Docker Tutorial:
https://tecadmin.net/tutorial/docker/docker-tutorials/Docker Commands
# docker login with username
docker login --username=rajacsp
Ref:
https://stackoverflow.com/questions/34434231/how-to-specify-username-and-password-upon-docker-push
docker —version
docker --version
Docker version 19.03.13, build 4484c46d9d
docker info
# List Docker images
docker image ls
docker images
# List all Docker running containers
docker ps -a
# Docker ps with grep including header
docker ps | grep 'rj\|IMAGE'
docker ps | sed '1!d' ; docker ps | grep "rj"
https://unix.stackexchange.com/questions/288521/with-the-linux-cat-command-how-do-i-show-only-certain-lines-by-number
https://www.baeldung.com/linux/combine-linux-commands
# List Docker containers
docker container ls -all
docker network ls
docker network create elastic
## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq
# Stop the container
docker stop <container_name>
docker ps -a
docker images
# run the docker image as a container
docker run -i -t ubuntu /bin/bash
docker run -i -t <id> /bin/bash
https://stackoverflow.com/questions/18497688/run-a-docker-image-as-a-container
# remove docker container
docker rm abcd
# remove docker image
docker rmi abcd
# docker run with detached
docker run -d abcd
# restart if exists
docker run --restart=always redis
# docker commit
docker commit --change "ENV DEBUG true" c3f279d17e0a svendowideit/testimage:version3
# run the static site
docker run -d -P seqvence/static-site
# verify the running site
http://localhost:32769/
Ref:
https://www.youtube.com/watch?v=lNkVxDSRo7M
# Start the existing container
docker start <container-name>
# docker run Ubuntu
docker run -it --name ubuntu ubuntu:xenial bash
# start existing ubuntu
docker start ubuntu
# get into bash
docker exec -it ubuntu bash
# docker exec
docker exec -it ubuntu bash
Run a command in a running container
https://docs.docker.com/engine/reference/commandline/exec/
# tty
https://unix.stackexchange.com/questions/21147/what-are-pseudo-terminals-pty-tty
#
docker status
https://www.cloudytuts.com/tutorials/docker/how-to-check-memory-and-cpu-utilization-of-docker-container/
#
docker image ls --format "{{ .Size }}" python:3.8-slim-buster
https://pythonspeed.com/articles/system-packages-docker/
# Install OracleDB
docker run -d -it --name ortest store/oracle/database-enterprise:12.2.0.1
docker exec -it ortest bash -c "source /home/oracle/.bashrc; sqlplus /nolog"
More:
https://hub.docker.com/u/rajacsp/content/sub-19df1a00-1ae1-4229-8fb6-96dc2b4703bf
# Connect from outside container:
docker run -d -it --name ortest -P store/oracle/database-enterprise:12.2.0.1
# Check Oracle logs in docker
docker logs ortest
# Start DB as DBA
docker exec -it ortest bash -c "source /home/oracle/.bashrc; sqlplus / as sysdba"
# dockering Flask
https://runnable.com/docker/python/dockerize-your-flask-application
# Build docker
docker build -t my_docker_flask:latest .
# run the docker flask image
docker run -d -p 4000:5000 rajacsp/flaskmath:2
# run the published docker image
docker run --publish host_port:container_port
docker run --publish 5000:5000 --detach --name flask-reverse-string rajakwikee/flask-reverse-string
https://hub.docker.com/r/rajakwikee/flask-reverse-string
# Docker basic app
https://docs.docker.com/get-started/
how to save a docker container as an image?
https://docs.docker.com/engine/reference/commandline/commit/#commit-a-container-with-new-cmd-and-expose-instructions
# run the public docker
docker run -p 4000:80 rajacsp/flaskcsp:p2
# Public docker:
https://hub.docker.com/r/jcdemo/flaskapp/dockerfile
# Stop all running containers
docker container stop $(docker container list -q)
https://linuxhint.com/stop_all_docker_containers/
# Clear docker / remove all containers / docker prune
docker system prune -a
https://linuxize.com/post/how-to-remove-docker-images-containers-volumes-and-networks/
docker volume prune
# delete all images
docker images | awk {'print $3'} | xargs docker rmi -f
docker container prune
docker container prune -f
https://docs.docker.com/engine/reference/commandline/container_prune/
# Kube pod details
kubectl get po
kubectl logs bapi-be-6db7bf6f95-bshhk
# Container life cycle
https://medium.com/@nagarwal/lifecycle-of-docker-container-d2da9f85959
# Docker copy
docker ps
docker cp foo.txt 72ca2488b353:/foo.txt
docker cp 72ca2488b353:/foo.txt foo.txt
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
https://www.shellhacks.com/docker-cp-command-copy-file-to-from-container/
Docker commit and push
docker pull ubuntu
docker run --name csp-lamp-server -it ubuntu:latest bash
apt-get update
apt-get install lamp-server^
docker commit -m "Added LAMP Server" -a "NAME" csp-lamp-server USER/test-lamp-server:latest
docker login
docker push rajacsp/csp-lamp-server
https://www.techrepublic.com/article/how-to-create-a-docker-image-and-push-it-to-docker-hub/
Create simple Flask Image:
http://containertutorials.com/docker-compose/flask-simple-app.html
Docker run vs exec:
https://medium.com/the-code-review/docker-run-vs-exec-deep-dive-into-their-differences-19a1041735a3
Docker logs:
Docker logs <container_id>
docker run -d -it --name myflask -p 5002:5000 rajacsp/my_docker_flask:latest
docker image inspect:
docker image inspect <imageid>
docker image inspect 5158108894a9
https://docs.docker.com/engine/reference/commandline/image_inspect/
Find ip of a docker container:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host
Expose in Dockerfile
https://we-are.bookmyshow.com/understanding-expose-in-dockerfile-266938b6a33dLast updated
Was this helpful?