Last active
May 13, 2018 20:51
-
-
Save psychok7/28301b82d41bd2c615eb to your computer and use it in GitHub Desktop.
Docker commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source: https://vimeo.com/133154447 | |
Source: https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/ | |
# if you run into problems when creating try docker-machine regenerate-certs dev | |
docker-machine create --driver virtualbox dev | |
# run commands in your created VM | |
eval "$(docker-machine env dev)" | |
# List available machines and check their Ip's | |
docker-machine ls | |
docker-machine stop dev | |
docker-machine start dev | |
# List containers | |
docker ps -a | |
# List images | |
docker images | |
# Remove container | |
docker rm <hash> | |
# Search by name and remove | |
docker ps -a | grep ' multitask_multi' | awk '{print $1}' | xargs --no-run-if-empty docker rm | |
# Remove images | |
docker rmi <name> | |
# Step into existing container | |
docker exec -it web /bin/bash | |
or | |
docker-compose run --rm web bash # remove created container after running it | |
docker-compose build | |
docker-compose up | |
# Stops containers and removes containers, networks, | |
docker-compose down | |
# Using docker compose to build a new container. If you find its taking too long try restarting the docker service and then "docker build -t web ." to make sure its starts building again. | |
docker-compose build web | |
# Recreate all services and run then in the background (production) | |
docker-compose -f staging.yml up -d --force-recreate | |
# recreate only 1 service | |
docker-compose -f staging.yml up -d --no-deps web | |
# remove old container and create new one. use --no-recreate so disallow loosing data like postgres data for example but to reload new configurations you should not use it | |
docker-compose rm --force web && docker-compose up --no-recreate web | |
# To enable an interactive TTY to debug the "web" service and use thinks like ipdb for example you must docker-compose kill web and after the starting all containers, and then run the following command. Use rm to remove the created container after it runs. | |
docker-compose -f dev.yml run --service-ports --rm web | |
# Stop all containers | |
docker-compose kill | |
# Remove all containers | |
docker-compose rm --force | |
u | |
# Using Logs | |
docker service logs | |
docker-compose logs web | |
# Delete all stopped containers. It will not delete running ones because it has no -f | |
docker rm `docker ps -aq` | |
# Delete all images | |
docker rmi $(docker images -q) | |
# Docker >=1.13.x | |
docker system df # will show used space, similar to the unix tool df | |
docker system prune # WARGING: will remove all data that is not running. | |
# Delete all untagged volumes. If you dont want to delete the running ones dont use -f | |
docker volume ls -f dangling=true | wc -l | |
docker volume ls -qf dangling=true | xargs -r docker volume rm # new way | |
# Delete all untagged images | |
docker rmi $(docker images -f "dangling=true" -q) | |
# If a file is created with a root ownership you can change it back with: | |
sudo chown psychok7:psychok7 -R station/ | |
# If you run into Permissions should be u=rwx (0700) | |
- Make sure permissions on host are "drwx------ 2 postgres postgres 4096 Abr 14 18:48 /var/lib/postgresql/data/" ??? # not sure about this one | |
- Remove the containers (docker ps -a | grep ' multitask' | awk '{print $1}' | xargs --no-run-if-empty docker rm) | |
- docker-compose build | |
- docker-compose up (if it throws errors let it finish and then restart it) | |
# I needed to downgrade so i did a apt-cache policy docker-engine to list the version and then sudo apt-get install docker-engine=1.10.3-0~trusty | |
# POSTGIS + Django + docker-compose | |
To use posgis simply after running docker-compose up for the first time, step into your WEB container (like Django for example) and run `python manage.py dbshell` (this will connect you to your remote postgis database and you can create the database and the postgis extention inside). | |
You don't have to follow the instruction from the official https://hub.docker.com/r/mdillon/postgis/ | |
Since there is gargabe in the postgres db that db shell automatically connects to you have 2 options: | |
1 - Delete this garbage: | |
drop schema public cascade; | |
create schema public; | |
> CREATE EXTENSION postgis; | |
> CREATE EXTENSION postgis_topology; | |
OR | |
2 - Create new db and change your django settings files to match that new db | |
Assuming you have your Port setup correctly you can connect to you Postgresql server from your host postgres client to import a dump for example: | |
psql -h project_postgis -p 5432 -U postgres postgres < _backups/dump.sql | |
# Step into MONGO container | |
docker exec -it <container_id> bash | |
# Connect PGADMIN to Docker Postgres Container | |
docker inspect <container_id> (to get the used port and IP of container then use that information to enter in PGADMIN) | |
Downgrade Docker | |
https://github.com/docker/docker/issues/15581#issuecomment-212848860 | |
Change docker folder location on Ubuntu 16.04 and 18.04: | |
https://stackoverflow.com/a/37589355/977622 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment