Guest User

Untitled

a guest
Nov 12th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. ## Installation
  2. ### Running docker as non-root user:
  3. sudo usermod -aG docker $USER
  4.  
  5. ### Dockerfile:
  6. ```yml
  7. FROM ubuntu:tag # Sets the image
  8. MAINTAINER Denis Policastro <denis.policastro@gmail.com>
  9. ADD . . # Copy items from host to VM (All from dir to workdir)
  10. COPY /src . # Files or dir
  11. LABEL Description=”Descrição do projeto” # Metadata, D version
  12. ENTRYPOINT [“usr/bin/apache2ctl”, “-D”, “FOREGROUND”] # Main process running on the container, if the process dies the container dies
  13. CMD [“node”, “app.js”] # Params for the entrypoint, example if entrypoint is a bash, ls is a param
  14. ENV TEST=”Test env” # Declare env vars
  15. USER denis # Sets the user, default is root
  16. WORKDIR /srv # Set working dir
  17. VOLUME /host/dir /container/dir
  18. ```
  19.  
  20. ### Running Container:
  21. ```sh
  22. docker run \
  23. -d | -it \ #Default -d
  24. [--publish | -p] \
  25. [--memory] \
  26. [--cpu-shares] \
  27. [--rm] \
  28. [--env | -e] \
  29. [--network] \
  30. [--net-alias] \
  31. [--name] \
  32. [-v] \
  33. nginx
  34. ```
  35.  
  36. --publish | -p: Specifies the exposed port
  37. HOST_PORT:CONTAINER_PORT
  38.  
  39. --cpu-shares: Sets the cpu share percent
  40. 512
  41.  
  42. --memory: # Specifies the max memory consumption for that container
  43. 512m
  44. --rm: # Automatic remove container when exit
  45.  
  46. --environment | -e: Sets environment variable
  47. MYSQL_RANDOM_ROOT_PASSWORD=yes
  48.  
  49. --network: Specifies the network
  50. NETWORK_NAME
  51.  
  52. --net-alias: Gives an alias for load balancing the containers inside the container network
  53. ALIAS
  54.  
  55. --name: Gives the container a name
  56. CONTAINER_NAME
  57.  
  58. -v: Bind a custom volume to the host from the container for persistent data
  59. named_volume:/var/lib/mysql
  60. ./mount/to/bind:/var/lib/mysql
  61.  
  62.  
  63. ##### Using net alias:
  64. Create two containers:
  65. docker container run -d --network es_network --net-alias search elasticsearch:2
  66. docker container run -d --network es_network --net-alias search elasticsearch:2
  67. Create another one for querying:
  68. docker container run -it --network es_network centos:7 bash
  69. nslookp search
  70. curl -s search:9200
  71.  
  72. ##### Containers config:
  73. docker container top
  74. docker container inspect --format=’{{ .NetworkSettings }}’ CONTAINER_ID
  75. docker container stats -> CPU, MEM
  76.  
  77. ##### Starting stopped container:
  78. docker start \
  79. # --attach --interactive \
  80. -ai \
  81. CONTAINER_NAME
  82.  
  83. ##### Interacting with running container:
  84. docker exec \
  85. -it \ #(--interactive --tty)
  86. CONTAINER_NAME \
  87. bash | command
  88.  
  89. ##### Change running container configuration:
  90. docker update --help
  91. Limits CPU, RAM
  92. docker run --memory 512m --cpu-shares 1024 --name nginx1 nginx:lastest
  93. docker run --memory 512m --cpu-shares 512 --name nginx2 nginx:lastest
  94. docker run --memory 512m --cpu-shares 512 --name nginx3 nginx:lastest
  95. docker container -m 256m nginx
  96. --cpu-shares: Percentage of cpus for each container, in this case nginx1 have 50%, nginx2 and nginx3 have 25% each.
  97.  
  98. ##### Networking
  99. docker network ls
  100. docker network inspect NETWORK_NAME
  101. docker network create NETWORK_NAME
  102. docker network connect NETWORK_NAME CONTAINER_NAME
  103. docker network disconnect
  104. Overlay: Used for docker swarm to communicate between containers
  105. Bridge: Used for containers network
  106.  
  107.  
  108. Docker-Compose
  109.  
  110. docker-compose up
  111. docker-compose top
  112. docker-compose down
  113. docker-compose build
  114. docker-compose up --build
  115.  
  116. Docker Swarm
  117.  
  118. docker info
  119. Check if swarm is enabled
  120. docker swarm init
  121. Initialize swarm’s master node
  122. docker service create alpine ping 8.8.8.8
  123. Creates a service
  124. docker service ls | docker service ps SERVICE_NAME
  125. Check service status
  126. docker service update SERVICE_NAME --replicas 3
  127. Changes service configuration
  128.  
  129. ##### Creating two services in the same network:
  130.  
  131. Create the overlay network, for communicating swarm services:
  132. docker network create --driver overlay mydrupal
  133.  
  134. Create the services, passing the --network:
  135. docker service create --name drupal --network mydrupal -p 80:80 drupal
  136.  
  137. docker service create docker service create --name psql --network mydrupal -e POSTGRES_PASSWORD=mypass postgres
  138.  
  139. ##### Changes service configuration:
  140. docker swarm update --help #Changes dynamic
  141.  
  142. ##### Configuring nodes:
  143.  
  144. docker swarm init --advertise-addr PUBLIC_IP
  145. This command generates an output, that needs to be executed on worker nodes
  146.  
  147. docker node update --role manager NODE_NAME
  148. Changes node role to manager
  149.  
  150. docker swarm join-token manager
  151. Generates the output to join the service as a manager
Add Comment
Please, Sign In to add comment