✏️
rjnotes
  • Home
  • Books To Read in 2023
  • Mac & Ubuntu Commands - v2
  • DevOps Tasks
  • AWS Commands
  • AWS IAM Policies
  • Autoscaling Automation
  • Shell Commands - Unix
  • RJTools
  • Github
  • VAP
  • virtualenv
  • Alembic Commands
  • Aerospike commands
  • AWS Lambda Commands
  • AWS Glue Commands
  • AWS IAM Policies
  • Azure Commands
  • Cassandra Commands
  • Clickhouse Commands
  • Conda Commands
  • Docker Commands
  • IV Assignments
  • AWS Pricing
  • LangChain Commands
  • Python templates
  • PyLint
  • Pandas Commands
  • CICD
  • GitBook - How to publish
  • HTTPS Fix
  • Video Fix
  • Sublime
  • YT Videos
  • Template
  • GenAI Cards
  • Assignment Validator
  • Auth
  • Decision Maker Persona
  • Session Time
  • New Language Learning
  • Finnish Learning
  • Paste Image Extension
  • Director vs Head vs VP
Powered by GitBook
On this page

Was this helpful?

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-266938b6a33d
Docker fresh build and deploy:

cd /Users/str-kwml0011/projects/docker-flask-reverse-string

docker build -t flask-reverse-string:latest .

# check your docker image
docker images

# check container
docker ps

# Run it
docker run -d -p 5000:5000 flask-reverse-string:latest

# Test
curl http://127.0.0.1:5000/

# tagging
docker tag flask-reverse-string rajacsp/flask-reverse-string

# Docker pruning
docker container prune
	https://docs.docker.com/config/pruning/
	
#
Docker daemon location
~/.docker/daemon.json

#
docker exec wordmeter_mlmeter_service ls 
It will show the files inside
	https://devconnected.com/docker-exec-command-with-examples/


docker compose convert
	https://docs.docker.com/compose/environment-variables/

Test:
http://127.0.0.1:5000/reverse?name=Raja
Docker Compose:

# verify docker compose
docker-compose config 

# start
docker-compose up

# start
docker-compose up -d build

# start with detached more
docker-compose up -d


docker-compose up --detach

# stop
docker-compose down

# 
docker-compose ps

#
docker-compose --help

#
docker-compose up -d --scale service_1=4 service_2=3

#
docker run --rm
	The flag --rm is used when you need the container to be deleted after the task for it is complete.
	https://stackoverflow.com/questions/49726272/what-is-the-rm-flag-doing
docker commands set 2:


https://linuxize.com/post/how-to-remove-docker-images-containers-volumes-and-networks/
Postgres:

https://hub.docker.com/_/postgres?tab=tags

docker pull postgres:alpine
docker run -d -it --name pg11 postgres:alpine
docker run --name pg11 -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres:alpine
docker exec -it pg11 bash


docker run -d -it --name pg11 postgres:11

docker run --name pg11 -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres:11

docker run --name pg11 -v /home/ubuntu/db/pg11_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres:11

docker run --name pg11 -v /Users/str-kwml0011/db/pg11_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres:11


docker exec -it pg11 bash

psql -U postgres

0.0.0.0

psql -h 0.0.0.0 -p 5432 -U postgres

DB cred:
u: postgres
p: root (or empty)

select current_database()

CREATE ROLE raja WITH LOGIN PASSWORD 'raja';
ALTER ROLE raja CREATEDB;
CREATE DATABASE raja;
GRANT ALL PRIVILEGES ON DATABASE raja TO raja;
\connect raja
ALTER ROLE raja lOGIN;  

docker exec -it pg11 psql -U raja

CREATE TABLE one (
    name INT 
);

INSERT INTO one (name) VALUES (1);
INSERT INTO one (name) VALUES (2);


SELECT * FROM one;

#
show databases
\l

#
show roles
\du

#
get current database:
select current_database();

#
switch database
\c db_name

#
list tables
\dt

CREATE TABLE city (
	id SERIAL,
	name VARCHAR (50),
	state VARCHAR (50)
);
INSERT INTO city (name, state) VALUES ('Chennai','TN');
INSERT INTO city (name, state) VALUES ('Toronto','ON');

CREATE TABLE city (
	id SERIAL,
	name VARCHAR (50),
	state VARCHAR (50),
	country VARCHAR (50)
);

INSERT INTO city (name, state, country) VALUES ('Chennai','TN', 'India');
INSERT INTO city (name, state, country) VALUES ('Bangalore','KA', 'India');
INSERT INTO city (name, state, country) VALUES ('Toronto','ON', 'Canada');

SELECT * FROM city;

GRANT ALL PRIVILEGES ON TABLE city TO raja;

#
Get the current DB:
SELECT current_database();
https://dba.stackexchange.com/questions/58312/how-to-get-the-name-of-the-current-database-from-within-postgresql


sudo docker run --rm -P -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD="1234" --name pg postgres:alpine

#
Export sql
docker exec -t pg11 pg_dumpall -c -U postgres > dump_rj_june.sql
https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database

#
Backup and restore:
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
docker exec pg11 pg_dumpall -c -U postgres raja > /

# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
https://gist.github.com/spalladino/6d981f7b33f6e0afe6bb

#
Dump specific DB:
docker exec <container_name> pg_dump <schema_name> > backup
docker exec pg11 pg_dump raja -U postgres > /Users/str-kwml0011/datasets/pg_raja_db.sql
https://stackoverflow.com/questions/30171063/how-to-generate-a-postgresql-dump-from-a-docker-container

#
Postgres create 
https://medium.com/coding-blocks/creating-user-database-and-adding-access-on-postgresql-8bfcd2f4a91e
docker run --name pg11 -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres
docker exec -it pg11 bash

psql -h 0.0.0.0 -p 5432 -U postgres

psql -h 165.225.36.90 -p 5432 -U postgres
psql -h 120.0.0.1 -p 5432 -U postgres
psql -h localhost -p 5432 -U postgres

172.17.0.3
psql -h 172.17.0.3 -p 5432 -U postgres

psql postgresql://postgres:root@localhost:5432/postgres

Connecting postgres:
https://stackoverflow.com/questions/37694987/connecting-to-postgresql-in-a-docker-container-from-outside


psql -h localhost  -U bob

Posgres issues:
https://github.com/docker-library/postgres/issues/41


Feature: ValueType:
Time
TimePair
Value Pair
XML
Year
Year Pair

Feature Value:
value, name, sorting
domain, 2nd domain

Value list (String)
global.properties
value-list-string = Value list (String)
<xe:option label="${value-list-string}" value="2"/>

Java synthetic class:
https://javapapers.com/core-java/java-synthetic-class-method-field/


Events:
ID

Simple product:
https://cms-dev.kwikee.com/Kwikee/product/3841108
GTIN: 00013000002691
ID: 3841108


# Find OS info in Docker
uname -a

sample:
Linux d95c0096bc3b 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 GNU/Linux

Distribution Engine:
https://github.com/KwikeeLabs/distribution-engine
Docker Distribution Engine Installation:

Steps to Setup the Distribution Engine on your VM:

Login to the VM
Install Docker: https://docs.docker.com/engine/installation/linux/ubuntulinux/ a. Refer to the Prerequisites, Install and Optional Configurations: Configure Docker to Start on Boot sections of the documentation b. Follow the associated Ubuntu version sections of the documentation c. To verify which version of Ubuntu being used, enter this command in the prompt: lsb_release -a
Install Docker Compose: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-14-04 a. Refer to "Step 2 - Installing Docker Compose"
Go to your personal project directory i.e. /home/(username)/project
Copy the kwikee.zip package to this directory
sudo apt-get install unzip
Unzip the package
Go inside the kwikee folder
sudo docker-compose up -d postgres rabbitmq
sudo apt-get install postgresql-client-common postgresql-client
psql -U kwikee -W -d kwikee -h localhost < kwikee.sql
Enter password for kwikee user: kwikee
sudo docker-compose up -d api worker
sudo docker-compose exec worker python manage.py init_db
sudo docker-compose up -d nginx
Influx DB:

https://hub.docker.com/_/influxdb

docker run --name=influxdb -d -p 8086:8086 influxdb

docker exec -it influxdb influx

Getting started with InfluxDB
https://docs.influxdata.com/influxdb/v1.7/introduction/getting-started/

https://www.influxdata.com/blog/getting-started-python-influxdb/

https://coderwall.com/p/fg18jq/getting-started-influxdb-grafana-docker

https://influxdb-python.readthedocs.io/en/latest/examples.html
String getCallbackUrl();


Mysql Docker Container:

docker pull mysql

docker run --name rjmysql -p 3306:3306 -v /Users/str-kwml0011/mysql_docker_v:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql

docker exec -it rjmysql bash

mysql -u root -p
root

show databases;

create db:
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost';

CREATE DATABASE rj;

USE rj;

CREATE TABLE city (id INT, name VARCHAR(40), state VARCHAR(40), country VARCHAR(40));

INSERT INTO city values (1, 'Madurai', 'Tamilandu', 'India');
INSERT INTO city values (1, 'Toronto', 'Ontario', 'Canada');

SELECT * FROM city;


MySQLConnectionTest.java

dump docker_mysql to .sql:
docker exec rjmysql sh -c 'exec mysqldump --all-databases -uroot -proot' > /Users/str-kwml0011/rjmysql_dump.sql
docker exec rjmysql sh -c 'exec mysqldump rj -uroot -proot' > /Users/str-kwml0011/rjdb_dump.sql

more:
https://hub.docker.com/_/mysql
https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql
https://www.cyberciti.biz/faq/howto-linux-unix-creating-database-and-table/
Docker Prune:

docker image prune

docker image prune -a

docker container prune

# include volumne as well
docker system prune -a --volumes

# including the running containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
    https://coderwall.com/p/ewk0mq/stop-remove-all-docker-containers

https://docs.docker.com/config/pruning/
Docker compose:

docker-compose up
docker-compose up --build

docker build vs docker-compose build
https://stackoverflow.com/questions/50230399/what-is-the-difference-between-docker-compose-build-and-docker-build

https://docs.docker.com/compose/gettingstarted/
https://docs.docker.com/compose/compose-file/
How to get into exited containers?

docker start `docker ps -q -l` && docker attach `docker ps -q -l`

https://bobcares.com/blog/docker-run-exited-container/
Docker volumes:

docker volume ls

	https://stackoverflow.com/questions/46866933/is-there-a-way-to-list-files-inside-a-docker-volume

docker volume ls -qf dangling=true

docker volume inspect my-vol

docker volume rm $(docker volume ls -qf dangling=true)
	https://stackoverflow.com/questions/36663809/how-to-remove-all-docker-volumes


docker volume rm aws-param-store-retriever_db
	
# remove docker voulme
docker volume rm -f 

# clean all docker volume
docker volume prune
How to increase docker memory
https://stackoverflow.com/questions/32834082/how-to-increase-docker-machine-memory-mac

How to get the ip of a container?
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pg11

how to limit the docker memory?
https://stackoverflow.com/questions/42345235/how-to-specify-memory-cpu-limit-in-docker-compose-version-3
Docker exit codes:

247 - Taking too much memory
	We depend on them to solve this issue of "eating memory". The server just kills the docker container because it's growing on memory a lot.
How to get into Dead/Exited container?


sol:
docker commit <exited_container_id> <new_image_name>
docker run -it <new_image_name> bash

sample:
docker commit de4462410125 aerospikedead
docker run -it aerospikedead bash


Now, you will get into exited container

	https://serverfault.com/questions/990147/enter-an-exited-docker-container-in-interactive-mode
docker tail

https://github.com/joemiller/docker-tail
tail -f .log file inside docker

https://dockerquestions.com/2021/10/06/cannot-tail-log-files-inside-docker-container/

docker logs tail -f container /app/logfile.log

docker logs -f cinfo_be_service /app/backend.log


docker exec -it cinfo_be_service tail -f /app/backend.log
How to install nettools in debian?

apt update

apt install net-tools

netstat -tulpn


netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      1/python
How to check os?

cat /etc/

PreviousConda CommandsNextIV Assignments

Last updated 2 years ago

Was this helpful?