Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Installation
- ### Running docker as non-root user:
- sudo usermod -aG docker $USER
- ### Dockerfile:
- ```yml
- FROM ubuntu:tag # Sets the image
- MAINTAINER Denis Policastro <denis.policastro@gmail.com>
- ADD . . # Copy items from host to VM (All from dir to workdir)
- COPY /src . # Files or dir
- LABEL Description=”Descrição do projeto” # Metadata, D version
- ENTRYPOINT [“usr/bin/apache2ctl”, “-D”, “FOREGROUND”] # Main process running on the container, if the process dies the container dies
- CMD [“node”, “app.js”] # Params for the entrypoint, example if entrypoint is a bash, ls is a param
- ENV TEST=”Test env” # Declare env vars
- USER denis # Sets the user, default is root
- WORKDIR /srv # Set working dir
- VOLUME /host/dir /container/dir
- ```
- ### Running Container:
- ```sh
- docker run \
- -d | -it \ #Default -d
- [--publish | -p] \
- [--memory] \
- [--cpu-shares] \
- [--rm] \
- [--env | -e] \
- [--network] \
- [--net-alias] \
- [--name] \
- [-v] \
- nginx
- ```
- --publish | -p: Specifies the exposed port
- HOST_PORT:CONTAINER_PORT
- --cpu-shares: Sets the cpu share percent
- 512
- --memory: # Specifies the max memory consumption for that container
- 512m
- --rm: # Automatic remove container when exit
- --environment | -e: Sets environment variable
- MYSQL_RANDOM_ROOT_PASSWORD=yes
- --network: Specifies the network
- NETWORK_NAME
- --net-alias: Gives an alias for load balancing the containers inside the container network
- ALIAS
- --name: Gives the container a name
- CONTAINER_NAME
- -v: Bind a custom volume to the host from the container for persistent data
- named_volume:/var/lib/mysql
- ./mount/to/bind:/var/lib/mysql
- ##### Using net alias:
- Create two containers:
- docker container run -d --network es_network --net-alias search elasticsearch:2
- docker container run -d --network es_network --net-alias search elasticsearch:2
- Create another one for querying:
- docker container run -it --network es_network centos:7 bash
- nslookp search
- curl -s search:9200
- ##### Containers config:
- docker container top
- docker container inspect --format=’{{ .NetworkSettings }}’ CONTAINER_ID
- docker container stats -> CPU, MEM
- ##### Starting stopped container:
- docker start \
- # --attach --interactive \
- -ai \
- CONTAINER_NAME
- ##### Interacting with running container:
- docker exec \
- -it \ #(--interactive --tty)
- CONTAINER_NAME \
- bash | command
- ##### Change running container configuration:
- docker update --help
- Limits CPU, RAM
- docker run --memory 512m --cpu-shares 1024 --name nginx1 nginx:lastest
- docker run --memory 512m --cpu-shares 512 --name nginx2 nginx:lastest
- docker run --memory 512m --cpu-shares 512 --name nginx3 nginx:lastest
- docker container -m 256m nginx
- --cpu-shares: Percentage of cpus for each container, in this case nginx1 have 50%, nginx2 and nginx3 have 25% each.
- ##### Networking
- docker network ls
- docker network inspect NETWORK_NAME
- docker network create NETWORK_NAME
- docker network connect NETWORK_NAME CONTAINER_NAME
- docker network disconnect
- Overlay: Used for docker swarm to communicate between containers
- Bridge: Used for containers network
- Docker-Compose
- docker-compose up
- docker-compose top
- docker-compose down
- docker-compose build
- docker-compose up --build
- Docker Swarm
- docker info
- Check if swarm is enabled
- docker swarm init
- Initialize swarm’s master node
- docker service create alpine ping 8.8.8.8
- Creates a service
- docker service ls | docker service ps SERVICE_NAME
- Check service status
- docker service update SERVICE_NAME --replicas 3
- Changes service configuration
- ##### Creating two services in the same network:
- Create the overlay network, for communicating swarm services:
- docker network create --driver overlay mydrupal
- Create the services, passing the --network:
- docker service create --name drupal --network mydrupal -p 80:80 drupal
- docker service create docker service create --name psql --network mydrupal -e POSTGRES_PASSWORD=mypass postgres
- ##### Changes service configuration:
- docker swarm update --help #Changes dynamic
- ##### Configuring nodes:
- docker swarm init --advertise-addr PUBLIC_IP
- This command generates an output, that needs to be executed on worker nodes
- docker node update --role manager NODE_NAME
- Changes node role to manager
- docker swarm join-token manager
- Generates the output to join the service as a manager
Add Comment
Please, Sign In to add comment