[DevOps] – How to use Docker to automate environments ?



Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

You will create containers by line commands.

Getting Started

Official  documentation : https://www.docker.com/products/docker#/mac 

Docker By Examples

Official  documentation : https://docs.docker.com/engine/tutorials/dockerizing/

What is a container ?

A container is the space where we isolate the execution of a process.


# connect

$ docker exec -i -t [container name] bash

# take id 

$ docker ps

# remove 

$ docker rm [id]

# remove more than one container 

$ docker rm $(docker ps -qa)

# remove images 

$ docker rmi [image name]

# initialize a container

$ docker start [container name]

# stop a container

docker stop [container name]

How to connecting the containers ?

Example :

# new ubuntu container

$ docker run ubuntu bash

# take the container id

$ docker ps -a

# run bash process inside of contaner

$ docker exec -it d98d5602dc26 bash

How to run a process within the container and make the process output is displayed in the terminal?

$ docker exec -it [id container] [process name]


$ docker exec -it d98d5602dc26 ps aux

How to kill a container ?

$ docker kill [id container]


To check : $ docker ps -a

Status of the finished container will find the number: 137 ( stopped by kill )

How to create a temp containers ?

$ docker run -it –rm ubuntu bash

How to install apache in a container ?

$ apt-get update && apt-get install -y apache2

How to define local ports  ?

$ docker run -it -p [local]:[container] ubuntu/apache bash

How to automating the creation of images?

You need create a Dockerfile file. This file is used to define the commands to be executed.

# Example :

FROM mysql //imagem base

RUN apt-get update && apt-get install -y apache2 //executa a instrução de instalação do Apache


CMD ["/usr/sbin/apache2clt", "-D", "FOREGROUND"]

How to add a directory in a container ?

FROM ubuntu //imagem base

RUN apt-get update && apt-get install -y apache2 //install apache

ADD app /var/www/html

CMD ["/usr/sbin/apache2clt", "-D", "FOREGROUND"]

Hot to copy files to inside of a container ?

FROM ubuntu //imagem base

RUN apt-get update && apt-get install -y apache2 //install apache
COPY app /var/www/html

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

How to create a bundle to save the keys ?

You need create a file-based key / value that serves as a flock to we store key values .

# Example :

Name : docker-compose.yml

    image: mysql
        - MYSQL_ROOT_PASSWORD=test123

    image: wordpress
        - WORDPRESS_DB_PASSWORD=test123
        - db:mysql
        - 80:80

How to keep saved data created in the container?

You must create a new file “docker-compose.yml” like as :

  image: mysql
    - ~/site/database/:/var/lib/mysql/

In this scenario: The database data is saved in the folder / var / lib / mysql within the container.

Screen Shot 2016-08-30 at 10.05.49 PM

What is the difference and how it works ?

Screen Shot 2016-08-30 at 10.01.19 PM




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s