Skip to content

Instantly share code, notes, and snippets.

@zshanabek
Last active January 21, 2024 17:12
Show Gist options
  • Save zshanabek/220e16015bbc4a2580df88748f23857f to your computer and use it in GitHub Desktop.
Save zshanabek/220e16015bbc4a2580df88748f23857f to your computer and use it in GitHub Desktop.
docker related commands
docker run --name pgacid -d -e POSTGRES_PASSWORD=postgres postgres:13
docker run -e POSTGRES_PASSWORD=postgres --name pg1 postgres. # -e for env variable. --name for container name. postgres is image.
docker exec -it pgacid psql -U postgres # -it interactive container. pgacid - name of container. postgres - user name. "docker exec" executes a command in a running container
docker start pgacid
docker run -it ubuntu # The combination of the -i and -t switches gives you interactive shell access into the container
docker images # To see the images that have been downloaded to your computer, type.
docker run hello-world
docker search ubuntu
docker pull ubuntu # command to download the official ubuntu image to your computer.
docker build . # build image from Dockerfile in current directory
docker exec -it thestrongest-db-1 /bin/sh
# Custom docker image
# Dockerfile
FROM postgres
COPY init.sql /docker-entrypoint-initdb.d
docker build -t pgshard . # build image
# End dockerfile
# run 3 database instances in terminal
docker run --name pgshard1 -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d pgshard
docker run --name pgshard2 -p 5433:5432 -e POSTGRES_PASSWORD=postgres -d pgshard
docker run --name pgshard3 -p 5434:5432 -e POSTGRES_PASSWORD=postgres -d pgshard
# run rabbitmq in docker
docker run --rm -it --hostname my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management
## docker compose
docker-compose up --build # build the image and run the container
docker-compose up -d # run the following command to run the process in the background. We don’t need to attach the --build flag as the images were already built.
docker-compose ps # view the currently running processes\
docker-compose down # kill the processes
docker-compose down -v # remove volumes
docker-compose exec db psql --username=hello_django --dbname=hello_django_dev
# container is an instance of the image
sudo docker compose run web django-admin startproject composeexample .
# This instructs Compose to run django-admin startproject composeexample in a container, using the web service's image and configuration.
# Because the web image doesn't exist yet, Compose builds it from the current directory, as specified by the build: . line in docker-compose.yml.
# Replication
docker run --name pmaster -p 5432:5432 -v /Users/jonasali/Documents/course_db/rep/pmaster_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres -d postgres
docker run --name pstandby -p 5433:5432 -v /Users/jonasali/Documents/course_db/rep/pstandby_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres -d postgres
docker logs pmaster
docker exec -it pmaster psql -U postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment