Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. # docker-compose
  2.  
  3. ```
  4. $ docker-compose -f ./docker-compose.yaml up -d
  5. $ docker logs -f [container_name]
  6. ```
  7.  
  8. > ## Index
  9.  
  10. - <a href="#mariadb">Mariadb </a>
  11. - <a href="#postgres">Postgres</a>
  12. - <a href="#ubuntu">Ubuntu</a>
  13.  
  14. ---
  15.  
  16. <div id="mariadb"></div>
  17.  
  18. ## Mariadb
  19.  
  20. > docker-compose
  21.  
  22. ```
  23. version: '3.4'
  24. services:
  25. mariadb:
  26. image: mariadb:10.2
  27. container_name: mariadb
  28. environment:
  29. MYSQL_ROOT_PASSWORD: pass
  30. MYSQL_DATABASE: testdb
  31. MYSQL_USER: tester
  32. MYSQL_PASSWORD: tester
  33. ports:
  34. - "3306:3306"
  35. logging:
  36. driver: syslog
  37. options:
  38. tag: "{{.DaemonName}}(image={{.ImageName}};name={{.Name}};id={{.ID}})"
  39. networks:
  40. - backend
  41. restart: on-failure
  42. volumes:
  43. - ${PWD}/mariadb:/var/lib/mysql
  44. networks:
  45. backend:
  46. driver: bridge
  47. ```
  48.  
  49. ```
  50. $ docker exec -it mariadb bash
  51. root@19d6c77a0f0e:/# mysql -u tester -p testdb
  52. Enter password:
  53. Welcome to the MariaDB monitor. Commands end with ; or \g.
  54. Your MariaDB connection id is 9
  55. Server version: 10.2.23-MariaDB-1:10.2.23+maria~bionic mariadb.org binary distribution
  56.  
  57. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  58.  
  59. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  60.  
  61. MariaDB [testdb]>
  62. MariaDB [testdb]>
  63. MariaDB [testdb]> show tables
  64. -> ;
  65. Empty set (0.01 sec)
  66.  
  67. MariaDB [testdb]> show databases;
  68. +--------------------+
  69. | Database |
  70. +--------------------+
  71. | information_schema |
  72. | testdb |
  73. +--------------------+
  74. 2 rows in set (0.00 sec)
  75. ```
  76.  
  77. ---
  78.  
  79. <div id="postgres"></div>
  80.  
  81. ## Postgres
  82.  
  83. > docker-compose
  84.  
  85. ```
  86. version: '3.1'
  87.  
  88. services:
  89. postgres:
  90. image: postgres
  91. container_name: postgres
  92. restart: always
  93. environment:
  94. - POSTGRES_PASSWORD=pass
  95. ports:
  96. - "5432:5432"
  97. ```
  98.  
  99. ```
  100. zaccoding@zaccoding:~/compose/postgres$ docker exec -it postgres bash
  101. root@f979f2462b94:/# psql -d postgres -U postgres
  102. psql (11.2 (Debian 11.2-1.pgdg90+1))
  103. Type "help" for help.
  104.  
  105. postgres=#
  106. ```
  107.  
  108. ---
  109.  
  110. <div id="ubuntu"></div>
  111.  
  112. ## Ubuntu
  113.  
  114. > Dockerfile
  115.  
  116. ```
  117. FROM ubuntu:16.04
  118.  
  119. RUN apt-get update && apt-get install -y openssh-server
  120. RUN apt-get install net-tools
  121. RUN mkdir /var/run/sshd
  122. RUN echo 'root:rootpw' | chpasswd
  123. RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  124. RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  125.  
  126. # SSH login fix. Otherwise user is kicked off after login
  127. RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
  128.  
  129. ENV NOTVISIBLE "in users profile"
  130. RUN echo "export VISIBLE=now" >> /etc/profile
  131.  
  132. EXPOSE 22
  133. CMD ["/usr/sbin/sshd", "-D"]
  134. ```
  135.  
  136. > build the image
  137.  
  138. ```
  139. $ docker build -t eg_sshd .
  140. ```
  141.  
  142. > docker-compose.yaml
  143.  
  144.  
  145. ```
  146. version: '3.4'
  147.  
  148. services:
  149. ubuntu:
  150. image: eg_sshd
  151. container_name: ubuntu
  152. tty: true
  153. ports:
  154. - "49154:22"
  155. ```
  156.  
  157. > ssh
  158.  
  159. ```
  160. $ ssh root@localhost -p 49154
  161. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement