Develop Intelligence - Docker Docker Compose
Develop Intelligence - Docker Docker Compose
version: '3.4'
networks:
frontend:
backend:
volumes:
v1:
v2:
services:
hellowebapp:
build:
context: ./HelloWebApp
dockerfile: Dockerfile
Develop Intelligence – Docker Docker Compose
image: hellowebapp
ports:
- "8081:80"
networks:
- frontend
- backend
volumes:
- v1:/mydemo
counterdemo:
build:
context: ./CounterDemo
dockerfile: Dockerfile
image: counterdemo
Building docker-compose.yml
1. Execute the following commands to build and run the docker container
docker build -t sandeepsoni/hellowebapp .
docker run --rm -p "8080:80" sandeepsoni/hellowebapp
Let us now replace the above docker run command with following docker-compose.yml
2. Add the following docker-compose.yml to the folder
version: '3.4'
services:
hellowebapp:
image: sandeepsoni/mydemoapp
ports:
- "8080:80"
3. Execute the following command
docker-compose up
Note that the above command has now replaced docker run command and did exactly same thing.
Use the below command to execute in DETACHED mode
docker-compose up -d
4. Execute the following command and note that all containers created by up command are deleted.
docker-compose down
5. Edit the docker-compose.yml as below. This time we are able to provide the build command also in docker-
compose yaml file.
version: '3.4'
services:
hellowebapp:
image: sandeepsoni/mywebserver
build:
context: .
Develop Intelligence – Docker Docker Compose
dockerfile: dockerfile
ports:
- "8080:80"
6. Execute the following command
docker-compose up
Note that the above command has now replaced docker build and run commands
Also note the WARNING: "Image for service hellowebapp was not built because it already existed. To rebuild this
image you must use `docker-compose build` or `docker-compose up --build
docker-compose up:
Builds, (re)creates, starts, and attaches to containers for a service.
If there are existing containers for a service, and the service’s configuration or image was changed after the
container’s creation, it picks up the changes by stopping and recreating the containers (preserving mounted
volumes)
Unless they are already running, this command also starts any linked services.
When the command exits, all containers are stopped.
docker-compose up -d
Starts the containers in the background and leaves them running.
docker-compose up hellowebapp
To run only the "hellowebapp" service from the yml file
docker-compose up --build
Force the creation of docker image.
docker-compose up --force-recreate
Force Compose to stop and remove existing containers and recreate all containers.
docker-compose down
Stops containers and removes containers, networks, volumes, and images created by up.
The -f flag is optional. If you don’t provide this flag on the command line, Compose traverses the working directory
and its parent directories looking for a docker-compose.yml and a docker-compose.override.yml file.
version: "3.2"
services:
myapi:
image: sandeepsoni/myapi
build:
context: .\DemoApi
dockerfile: Dockerfile
environment:
ASPNETCORE_ENVIRONMENT: Development
ConnectionString: "Server=mssqlserver;Database=CatalogDb;User Id=sa;Password=Password_123"
container_name: myapicontainer
ports:
- "5100:80"
- "5101:443"
depends_on
- mssqlserver
mssqlserver:
image: <xyz>
ports
- 1433:1433
webapp:
image: sandeepsoni/webmvc
build:
context: .\WebApp
dockerfile: Dockerfile
environment:
Develop Intelligence – Docker Docker Compose
- ASPNETCORE_ENVIRONMENT=Development
- WebAPIUrl=http://myapi
container_name: webappcontainer
ports:
- "8080:80"
- "5201:443"
depends_on:
- myapi
Wordpress lab
• Build a new Docker Compose file
• Use two Docker Hub images. One for Wordpress, and the other a Mysql image. You’ll need to review the
documentation for the images to find out what important options to pass the containers.
• Bring the stack up and try to use the blog.