Docker commands

Create a new user

    $ sudo groupadd docker
    $ sudo usermod -aG docker $USER

    Reboot

    $ newgrp docker

    Remove All docker images

    sudo docker image prune --all

    Remove all containers 

     sudo docker rm $(sudo docker ps -aq)

    Remove Images that are not associated with containers

    docker image prune -a

    docker image prune -a --filter "until=12h"

    Shell into a docker container 

    docker exec container_name sh
    Restart Docker
    sudo systemctl restart docker.socket docker.service
    Stop all the containers
    docker stop $(docker ps -a -q)


    Remove all the containers
    docker rm $(docker ps -a -q)

    Remove a specific docker image

    docker rmi imageid

    Force restart

    sudo systemctl restart docker.socket docker.service

    Generate tagged build using a specific docker file in the current context


     docker build -f Dockerfile.build -t  web:latest . 

    Run the image in a container with attached env-file


    docker run --name django-heroku -e "PORT=8765" -e "DEBUG=1" -p 8007:8765 --env-file ./backend/.envs/.production/.postgres web:latest

    Multiple .env files
    docker run --name django-heroku -e "PORT=8765" -e "DEBUG=1" -p 8007:8765 --env-file ./backend/.envs/.production/.postgres --env-file ./backend/.envs/.production/.django web:latest

    Should run on: localhost:8007 mapped to the containers 8765 port
    OR if using Gunicorn to serve the static files : http://0.0.0.0:8007/

    Stop and remove the containerdocker 


    docker stop django-heroku
    rm django-heroku

    Basinc Logging


    docker logs django-heroku

    Print env variables 

    docker exec -it  django-heroku bash -c 'echo "$POSTGRES_DB"'
    Execution in interactive mode with pseudo console

    View all exported variables 
    docker exec -it  django-heroku bash -c 'export -p'

    Create superuser and execute other django commands  (attach if necessary to an env file)

    docker exec -it  django-heroku bash -c 'python3 manage.py createsuperuser' 

    Execute static files admin 
    docker exec django-heroku ls /app/backend/staticfiles/admin




    Commentaires

    Posts les plus consultés de ce blog

    Kubectl Commands

    HMS Interface Translation