serving the solutions day and night


Sunday, August 16, 2020

Docker Compose

 Docker Compose is a tool that can execute containers from a YAML configuration file.
 Create docker-compose.yaml in the c:\myapp\ folder (code in c:\myapp\frontendmvc). 

For each service, specify the image or the Dockerfile path for the creation of the image, the ports to map to the container, and eventually,  the volumes and environments variables. 

Specify that a service depends on another service,  so that Docker Compose can run the containers in the right order. For example, the configuration for our frontendmvc is the following. 

Create a service from an image that it has to build from the Dockerfile (omitted because it is the standard name)  in the folder ./frontendmvc. 

When the image is built, it can run the container exposing the ports 8080 and, this container depends on the service sqlserver,  so the system has to start the sqlserver service first, and the frontendmvc afterward. 

The sqlserver service uses the image, exposes the port 1433, and sets the environment variables to configure SQL Server. 

Compose app using Docker Compose. From the myapp folder, execute the cmd. "docker-compose up" 

The composer creates the container myapp_ss2017withoutmount_1, myapp_frontendmvc_1 and attaches the database to the frontendmvct through the creation of a  default network named myapp_default. 

When the myapp_sqlserver_1 container starts up, the entry point of the frontendmvc is executed and starts.



To Navigate https://localhost:8080/. Very convenient
To restart restart the application, the command "docker-compose up".
To rebuild this image, command is `docker-compose build` or `docker-compose up --build`.
To Execute the command "docker-compose start" with out interactive mode
To stop , "docker-compose stop". 
To delete the containers (not image, but will delete default network), "docker-compose down". 

Production docker compose

docker-compose -f up 


No comments: