@@ -153,13 +153,289 @@ Docker Compose - это инструмент для определения и з
153153
154154![ docker-compose-example] ( /assets/images/docker/docker/docker-compose.png )
155155
156+ ---
157+
158+ # Docker commands
159+
160+ --
161+
162+ # Pull image from DockerHub
163+ <br >
164+
165+ ``` bash
166+ docker pull hello-world
167+ ```
168+
169+ --
170+
171+ # Run image. If image not exists locally then pull it from DockerHub
172+ <br >
173+
174+ ``` bash
175+ docker run hello-world
176+ ```
177+
178+ --
179+
180+ # Build image from the Dockerfile
181+ <br >
182+
183+ ``` bash
184+ docker build -t < image_tag> - < Dockerfile
185+ ```
186+
187+ and then you can run it in interactive mode:
188+
189+ ``` bash
190+ docker run -it < image_tag> bash
191+ ```
192+
193+ or run in deamon mode
194+
195+ ``` bash
196+ docker run -d < image_tag> rails s
197+ ```
198+
199+ or just run, execute command and stop
200+
201+ ``` bash
202+ docker run < image_tag> uname -a
203+ ```
204+
205+ --
206+
207+ # Display running containers
208+ <br >
209+
210+ ``` bash
211+ docker ps
212+ ```
213+
214+ If you want to see all containers - live and dead, so just add ` -a ` to commant:
215+
216+ ``` bash
217+ docker ps -a
218+ ```
219+
220+ --
221+
222+ # Execute command in running container
223+
224+ You can run command and get output:
225+ ``` bash
226+ docker exec < container_id or name> some command
227+ ```
228+
229+ or run command in interactive mode:
230+ ``` bash
231+ docker exec -it < container_id or name> rails c
232+ ```
233+
234+ --
235+
236+ # Managing images
237+ <br >
238+
239+ ## List images
240+ <br >
241+
242+ ``` bash
243+ docker images ls
244+ ```
245+
246+ ## Remove image
247+ <br >
248+
249+ ``` bash
250+ docker rmi < image_id or tag>
251+ ```
252+
253+ --
254+
255+ # Managing volumes
256+ <br >
257+
258+ ## List volumes
259+ <br >
260+
261+ ``` bash
262+ docker volume ls
263+ ```
264+
265+ ## Create volume
266+ <br >
267+
268+ ``` bash
269+ docker volume create < name>
270+ ```
271+
272+ ## Remove volume
273+ <br >
274+
275+ ``` bash
276+ docker volume rm < name>
277+ ```
278+
279+ --
280+
281+ ## Delete everything (containers, images, volumes, networks) in one command
282+ <br >
283+
284+ ``` bash
285+ docker system prune -af
286+ ```
287+ #### Be very careful with this command!
288+
289+ --
290+
291+ # Inspect container logs
292+ <br >
293+
294+ ``` bash
295+ docker logs < container_id or name>
296+ ```
297+
298+ --
299+
300+ # Inspect container metadata
301+ <br >
302+
303+ ``` bash
304+ docker inspect < container_id or name>
305+ ```
306+
307+ ---
308+
309+ # Docker Compose commands
310+
156311--
157312
158- ## Задание
313+ # Build images
314+ <br >
315+
316+ ``` bash
317+ docker-compose build
318+ ```
319+
320+ --
321+
322+ # Run containers
323+ <br >
324+
325+ ``` bash
326+ docker-compose up
327+ ```
328+
329+ --
330+
331+ # Build and run containers
332+ <br >
333+
334+ ``` bash
335+ docker-compose up --build
336+ ```
337+
338+ --
339+
340+ # Stop all containers
341+ <br >
342+
343+ ``` bash
344+ docker-compose down
345+ ```
346+
347+ ---
348+
349+ # Popular questions
350+
351+ --
352+
353+ ## How to seed DB in container?
354+ <br >
355+
356+ Let's image that you already have running containers, but empty database,
357+ so to seed you just need to execute one command:
358+ ``` bash
359+ docker exec -it < rails_container_id> rake db:seed
360+ ```
361+
362+ --
363+
364+ ## How to debug dockerized application?
365+ <br >
366+
367+ Just attach to the running rails container
368+ ``` bash
369+ docker attach < rails_container_id>
370+ ```
371+ and magic...
372+
373+ ---
374+
375+ # Usefull links
376+
377+ --
378+
379+ ## Documentation:
380+
381+ [ DockerHub] ( https://hub.docker.com/ )
382+
383+ [ Docker build docs] ( https://docs.docker.com/engine/reference/commandline/build/ )
384+
385+ [ Docker run docs] ( https://docs.docker.com/engine/reference/commandline/run/ )
386+
387+ [ Docker volume docs] ( https://docs.docker.com/storage/volumes/ )
388+
389+ [ Docker compose docs] ( https://docs.docker.com/compose/ )
390+
391+ [ Docker security docs] ( https://docs.docker.com/engine/security/ )
392+
393+ --
394+
395+ ## Courses
396+
397+ [ Official docker course] ( https://www.docker.com/play-with-docker )
398+
399+ [ Docker interactive course] ( https://www.katacoda.com/courses/docker )
400+
401+ --
402+
403+ ## Utils
404+
405+ A tool for exploring a docker image, layer contents, and discovering ways to shrink the size of your Docker/OCI image:
406+
407+ [ Dive] ( https://github.com/wagoodman/dive )
408+
409+ <br >
410+
411+ The Docker Bench for Security is a script that checks for dozens of common best-practices around deploying Docker containers in production:
412+
413+ [ Docker Bench Security] ( https://github.com/docker/docker-bench-security )
414+
415+ <br >
416+
417+ VScode extension
418+
419+ [ Link] ( https://code.visualstudio.com/docs/containers/overview )
420+
421+ --
422+
423+ # Materials from this lecture
424+
425+ https://github.com/bl0rch1d/docker_lecture_materials
426+
427+ ---
428+
429+ # One more thing...
430+
431+ ---
432+
433+ ``` bash
434+ git clone https://github.com/bl0rch1d/docker_lecture_materials.git
435+
436+ cd docker_lecture_materials
159437
160- - Развернем наше Web-приложение локально с помощью Docker и Docker-compose.
161- - Развернем staging-окружение приложения на AWS.
162- - Развернем production-окружение приложения на AWS.
163- - Настроим тестовое окружение и continuous integration для staging и production окружения с помощью CircleCI.
438+ docker build -t sw_movie - < ./dockerfiles/simple.Dockerfile
164439
165- ## [ Решение] ( https://dou.ua/lenta/articles/rails-tutorial-docker-1 )
440+ docker run -it sw_movie telnet towel.blinkenlights.nl
441+ ```
0 commit comments