This is an old revision of the document!


01. [00p] Running a multi-container application

Subtasks
  1. based on the sources and the Dockerfile in the api folder from the lab archive, build an image with the name api-lab4-image
  2. create a bridge network called lab4-db-network
  3. create another bridge network called lab4-adminer-network
  4. create a volume named lab4-db-volume
  5. launch a container in the background for a database with the following features:
    1. a bind mount will be attached that will map between the ./database/init-db.sql file on the local machine (this will be the source to the bind mount flag and can be found in the lab archive) and the /docker-entrypoint-initdb.d/init-db.sql file in the container to be run (this will be the destination)
    2. attach the previously-created lab4-db-volume volume (as source) to the /var/lib/postgresql/data path in the running container (as destination)
    3. the container will be part the previously-created lab4-db-network and lab4-adminer-network networks
    4. the following environment variables will be specified (in a docker run command, this is done as follows: docker run -e NAME=value):
      1. environment variable POSTGRES_USER with value admin
      2. environment variable POSTGRES_PASSWORD with value admin
      3. environment variable POSTGRES_DB with value books
    5. the container you run will be called lab4-db
    6. you will run the postgres image from the official register
  6. Start a container with the previously created image api-laborator-1-image in the background, with the following features:
    1. the container will run on the previously created laboratory1-db-network network
    2. the following environmental variables will be specified:
      1. variable PGUSER with value admin
      2. variable PGPASSWORD with value admin
      3. variable PGDATABASE with the value books
      4. variable PGHOST with value laboratory1-db
      5. variable PGPORT with value 5432
    3. the rolled container will be called laborator1-api
    4. the container will display port 80 and map it to port 5555 on the local machine.
  7. Check that the two containers are running properly and have connectivity:
    1. using Postman or any other similar application, make GET and POST requests on books (for a tutorial on Postman, you can enter aici)
    2. a JSON body with the format {"title": "title", "author": "author"} is expected for POST requests
    3. GET applications will return a list of books added by POST applications.
  8. Verify that the volume you added keeps the data persisting:
    1. stop and delete the two containers
    2. restart the two containers with the same commands as before
    3. send a GET request
    4. If you set it up correctly, you will receive a list of previously added books.
What to upload
  • a screenshot showing the successful execution of the Hello World container
ii/labs/s2/04/tasks/01.1652872839.txt.gz ยท Last modified: 2022/05/18 14:20 by radu.ciobanu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0