Docker CLI
docker pull <image_name> | pulls image from repo |
docker run image_name:9.6 | download and run with spec.version, run creates container from image. start just start it |
docker ps | list all runninig containers |
docker images | list all mages |
docker run -d <image_name> | run in detached mode (background) |
docker stop <container-ID> | stops container |
docker start <container-ID> | restarts container |
docker ps -a | list all (running and not running) |
docker run -p5000:3180 | port binding HOST_port:CONTAINER_port |
docker logs <container_ID> | display logs |
docker run –name <some_name> <image_name> | give name to a container |
docker exec -it <container_id> /bin/bash | get terminal of continer (env for enviroments) /bin/sh in case there is no /bin/bash |
docker network ls | internal docker network list |
docker network create <network_name> | create new network inside docker |
docker run -p 27017:27017 -d \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MOONGO_INITDB_ROOT_PASSWORD=passw \ –name mongodb \ –net mongo-network \ mongo | start mongodb, set ports, set network, set credentials. |
docker run -d \ -p 8081:8081 \ -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \ -e ME_CONFIG_MONGODB_ADMINPASSWORD=passw \ –net mongo-network \ –name mongo-express \ -e ME_CONFIG_MONGODB_SERVER=mongodb \ mongo-express | connect mongo UI, to mongoDB |
docker-compose -f <yaml_file> up | run containers with yaml config file |
docker-compose -f <yaml_file> down | shutdown containers and network |
### Docker compose ###
### .yaml file example ###
version: '3' ### docker compose version
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=passw
mongo-express:
image: mongo-express
ports:
- 8080:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=passw
- ME_CONFIG_MONGODB_SERVER=mongodb
### Dockerfile - Build image file ### filename has to be Dockerfile
FROM <image> ### usually some linux distro or app or...###
ENV MONGO_DB_USERNAME=admin \ ### or some other app credentials###
MONGO_DB_PASSWORD=passw ### optional, to avoid to change .yaml
RUN mkdir -p /home/app ### execute linux command inside container
### it will make dir inside container
COPY . /home/app ### copy content from host to container
CMD ["node"."/home/app/server.js"] ### or whatever has to be started inside
### -- entry point command
docker build -t <app-image-name:ver_xx> .
### Dockerfile must exist in the current dir ###
docker rm <container_id> | remove container |
docker rmi <image_id> | delete image |
### Private repository (docker registry) ###
### Create private repository on AWS ### (repo per image)
docker login ###copy command from repo provider (AWS)
### AWS cli must be installed and credentials configured
###image naming in docker registry
registryDOMAIN/imageName:tag
### rename image
docker tag myAPP:1.0 domain/myAPP:10
### push to repo
docker push domain/myAPP:10
docker run -v /home/myapp/mysql:/var/lib/mysql/data | mount volume host:container (host volumes) |
docker run -v /var/lib/mysql/data | docker will chose where to mount /var/lib/docker/volumes/random_hash/_data (anonymus volume) |
docker run -v name:/var/lib/mysql/data | named volumes. like anonymus but you can reference volume by name (mostly used) |
version: '3' ### docker compose version
services:
mongodb:
image: mongo
ports:
- 27017:27017
volumes:
- data-db:/var/lib/mysql/data #### named volume
#####################
some other config
#####################
### you have to list all volumes at the end
volumes: ### at services level
data-db: ### multiple containers can use one volume
driver: local
### docker volumes locations ###
C:\ProgramData\docker\volumes\ ### Win
/var/lib/docker/volumes/ ### Linux
/var/lib/docker/volumes/ ### OSX
### docker for mac creates linux VM
screen ~/Library/Containers/com.docker.docker/data/com.docker.docker.driver.amd64-linux/tty
### to get terminal of linuxVM on OSX ###
### Ctrl+a+k for exit ###
previous - next
Leave a Reply