Skip to content

Instantly share code, notes, and snippets.

@AtulKsol
Last active June 3, 2019 07:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AtulKsol/9d4fdaff872b54037bdbf0713d8907d6 to your computer and use it in GitHub Desktop.
Save AtulKsol/9d4fdaff872b54037bdbf0713d8907d6 to your computer and use it in GitHub Desktop.
Docker commands

Container's IP Address

  • docker inspect CONTAINER-ID | grep IPAddress

Container IP address using docker-compose

  • docker-compose ip

Stop and remove all container

  • docker stop $(docker ps -a -q)
  • docker rm $(docker ps -a -q)

Remove all images

  • docker rmi $(docker images -q)

Run bash terminal

  • docker-compose run web bash

OR

  • docker exec -it CONTAINER-ID /bin/bash

The -t option opens up a terminal, and the -i option makes it interactive. The /bin/bash options opens a bash shell to the running container.

Stops containers and removes containers, networks, volumes, and images created by up.

Run postgresql container and use psql

  • run --name db -d -e POSTGRES_PASSWORD=docker -e POSTGRES_USER=docker postgres
  • docker exec -it db psql -U docker postgres # postgres is optional

Debugging Rails with pry within a Docker container

  1. docker-compose up -d && docker attach web

Details can be found here.

  1. docker-compose run --service-ports web

docker-compose run creates a TTY session for your app to connect to, allowing interactive debugging. The default docker-compose up command does not create a TTY session.

Use docker without sudo in ubuntu

http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo

Restore database dump (.dump file) in docker db container

  1. Enter db container

docker exec -it db /bin/bash

  1. Create database using psql

psql -U postgres create database DATABASE_NAME;

  1. Copy dump to db container

docker cp DB_DUMP.dump $(docker-compose ps -q db):/

  1. Restore dump using pg_restore

pg_restore -U postgres --no-owner -d DATABASE_NAME < DB_DUMP.dump

@AtulKhanduri
Copy link

Official doc for using docker without sudo in ubuntu:
https://docs.docker.com/engine/installation/linux/linux-postinstall/

@AtulKhanduri
Copy link

Links to install docker(CE) and docker-compose:

Docker Community Edition (CE)

Docker Compose

@ksolvesnutra
Copy link

ksolvesnutra commented Jan 4, 2018

Compressed Backup:

Backup:
pg_dump -h localhost -p 5432 -U postgres -d mydb | gzip > backup.gz

Restore:
gunzip -c backup.gz | psql -h localhost -p 5432 -U postgres -d mydb

@Guri-ksolves
Copy link

Kill server running on some port number

$ lsof -wni tcp:
Then, use the number in the PID column to kill the process:

$ kill -9 PID

@AtulKsol
Copy link
Author

AtulKsol commented Jun 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment