# Learning Docker for myself (2) - Muti-Container ## Study notes mainly based on https://docker-curriculum.com ## Prerequisites If don't have basic knowledge about Docker, you could check [Learning Docker for myself (1) - Single Docker](https://hackmd.io/@d7E-vJZTRiKNHg9Jmbg5dA/ByD_2rWFi) ## Local Multi-containers ### Get the demo code ```console $ git clone https://github.com/prakhar1989/FoodTrucks $ cd FoodTrucks $ tree -L 2 ## tree function need to be installed with brew https://formulae.brew.sh/formula/tree . ├── Dockerfile ├── README.md ├── aws-compose.yml ├── docker-compose.yml ├── flask-app │ ├── app.py │ ├── package-lock.json │ ├── package.json │ ├── requirements.txt │ ├── static │ ├── templates │ └── webpack.config.js ├── setup-aws-ecs.sh ├── setup-docker.sh ├── shot.png └── utils ├── generate_geojson.py └── trucks.geojson ``` As the demo app have two parts, Flask process and Elastic Search (ES) process, we will take this nature to separate them to two containers. ### Establish Elastic Search container For ES, we could pull the "officially supported" image for ES. As Elastic, the company own the ES maintains their [own registry](https://www.docker.elastic.co/r/elasticsearch), we pull the image as following: ```console $ docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2 ``` and run it in development mode by: 1. specifying ports 2. setting and environment variable that configure the ES cluster to run as single-node ```console $ docker run --platform linux/amd64 -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2 ``` <font color="#f00">**Note**</font>: Not sure if this is apple silicon chip only, but if you see error message ++The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested++ please add `--platform linux/amd64` The above action may take a while, you can track the container log with following: ```console $ docker container logs es ``` The ES container established once you see the line: `[2022-12-30T23:54:46,870][INFO ][o.e.l.LicenseService ] [hZYdsnq] license [252d8ef0-bec4-4423-861e-39c0b6253069] mode [basic] - valid` You can try to send a request to ES container to verify it, by using <font color="#f00">`9200`</font> port to send a <font color="#f00">`cURL`</font> request: ```console $ curl 0.0.0.0:9200 { "name" : "hZYdsnq", "cluster_name" : "docker-cluster", "cluster_uuid" : "0iRkw9PwSGSTWPGk16gQTg", "version" : { "number" : "6.3.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "053779d", "build_date" : "2018-07-20T05:20:23.451332Z", "build_snapshot" : false, "lucene_version" : "7.3.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } ``` ### Establish Flask container We will use the Dockerfile as following: It is suggested to read this for more info abt ```yaml= # start from base image, we use ubuntu:18.04. # It's a Long term support FROM ubuntu:18.04 LABEL maintainer="Prakhar Srivastav <prakhar@prakhar.me>" # install system-wide deps for python and node # What is python3-dev? https://blog.csdn.net/chengyq116/article/details/100595448 # What is gnupg? https://blog.miniasp.com/post/2022/05/11/gnupg RUN apt-get -yqq update RUN apt-get -yqq install python3-pip python3-dev curl gnupg RUN curl -sL https://deb.nodesource.com/setup_10.x | bash RUN apt-get install -yq nodejs # copy our application code ADD flask-app /opt/flask-app WORKDIR /opt/flask-app # fetch app specific deps ## Line 20 Added to avoid error from next step RUN npm install RUN npm run build RUN pip3 install --upgrade pip RUN pip3 install -r requirements.txt # expose port EXPOSE 5000 # start app CMD [ "python3", "./app.py" ] ``` ----- ## Reference ###### tags: `Docker` `AWS`