Skip to content

Instantly share code, notes, and snippets.

@AtulKhanduri
Forked from AtulKsol/docker-commands.md
Last active November 23, 2017 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AtulKhanduri/59de3303b557e402252908a5055bf0a3 to your computer and use it in GitHub Desktop.
Save AtulKhanduri/59de3303b557e402252908a5055bf0a3 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 of docker container

  • docker-compose run web bash

OR

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

Run bash terminal of docker image

  • docker run -it --entrypoint=/bin/bash IMAGE_NAME

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 container-name

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

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