Skip to content

Latest commit

 

History

History
 
 

chapter3

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Chapter 3

3.1 Introduction to Docker Compose

Slides

  1. Installed as part of Docker Toolbox or github.com/docker/compose/releases

  2. docker-compose -v

  3. docker-compose --help. Explain up, ps, down, scale, restart, port

3.2 Docker Compose file

  1. Create a directory helloweb

  2. Create Compose file in helloweb directory: vi docker-compose.yml

version: '3'
services:
  web:
    image: jboss/wildfly
    volumes:
      - ~/deployments:/opt/jboss/wildfly/standalone/deployments
    ports:
      - 8080:8080
  1. Talk about how deployments directory is automatically created

  2. Explain web, image, volumes, ports

  3. Compare with Docker CLI

Run the commands:

docker-compose up -d
docker-compose logs -f
cp docker-for-java-master/chapter2/webapp.war ~/deployments
curl http://localhost:8080/webapp/resources/persons
docker-compose down

3.3 Multi-container application

  1. Create a directory travel

version: '3'
services:
  web:
    image: arungupta/couchbase-javaee:travel
    environment:
      - COUCHBASE_URI=db
    ports:
      - 8080:8080
      - 9990:9990
    depends_on:
      - db
  db:
    image: arungupta/couchbase:travel
    ports:
      - 8091:8091
      - 8092:8092
      - 8093:8093
      - 11210:11210
  1. Two images web and db

  2. Explain depdends_on - container and app starting sequence

  3. COUCHBASE_URI - show code

  4. Start application: docker-compose up -d

  5. Show logs: docker-compose logs -f

  6. Access application: curl http://localhost:8080/airlines/resources/airline

  7. Shutdown application: docker-compose down

3.4 Docker Compose options

Project name

By default, service names is <project-name>_<service-name>_<service-number> Start using docker-compose -p myapp up -d docker-compose ps shows no services docker-compose -p myapp ps shows services

Default Override

Copy the following in docker-compose.override.yml:

version: "3"
services:
  web:
   ports:
     - 80:8080
  1. Run application: docker-compose up -d.

  2. App now accessible at curl http://localhost/webapp/resources/persons

  3. Shutdown using docker-compose down

3.5 Docker Compose options

Slides only