Summaries/Overig/Docker/commands.md

2.4 KiB

Docker

This container runs in background

docker run -d -it --gpus all -name pytorch-container pytorch/pytorch:latest
docker run -d -it --rm -v $(pwd):/src --gpus all -name pytorch-container pytorch/pytorch:latest

Test GPU

>>> import torch
>>> print(torch.cuda.is_available())

The latter removes the docker instance when stopped and alse has a volume

Connect to running container

docker exec -it <container-name> bash
docker exec -it <container-name> bash -c "cat aap"

Stop and start an execistion container

docker stop <container-name>
docker start <container-name>

docker ipaddress or running container

docker inspect <container-name or id> | grep '"IPAddress"' | head -n 1

Run Postgresql daemon and psql attach

docker run --name my-postgres -e POSTGRES_PASSWORD=qw12aap -d postgres:latest
docker exec -it my-postgres psql -h localhost -U postgres -d postgres

inside: psql -U postgres -h my-postgres

docker files

FROM python:latest
RUN pip3 install numpy
CMD python3 /src/hello-world.py

docker networks

docker network create net_1

docker run --rm -d --net net_1 --name my_py -v $(pwd):/src  python:latest python3 /src/run.py

docker run --rm -it --net net_1 alpine:latest /bin/bash

docker network create net_2
docker run --rm --name my-postgres --network net_2 -e POSTGRES_PASSWORD=qw12aap -d postgres:latest
docker run -it --rm --name my_postgre2 --network net_2  postgres:latest /bin/bash

Docker Compose; Container Network is created automatically

version: '3'
services:
     python:
             image: python:latest
             container_name: my_py
             volumes:
                     - .:/src
             command: python3 /src/run.py
             restart: always
     postgres:
             image: postgres:latest
             container_name: my_post
             environment:
                     - e POSTGRES_PASSWORD=qw12aap
             restart: always
     alpine:
             image: alpine:latest
             command: echo "hello from alpine"
             restart: always

How To Remove Docker Images, Containers, and Volumes

How to Troubleshoot “Cannot Connect to the Docker Daemon” Errors