In the continuation of the following article I wrote earlier, I will create a Dockerfile and docker-compose.yml and describe the procedure to run it this time. https://qiita.com/MCYamamoto/items/4d424af9573fa90edf61
First, the final folder structure. It will be as follows.
base folder
+docker-compose.yml
+cont
+env
+Dockerfile
+deploy //Source code to be deployed(This time nodejs)
+package.json
+package-lock.json
+build
+js files
+share //Shared folder for host and container
[Reference URL] https://qiita.com/pottava/items/452bf80e334bc1fee69a
For the overall flow, the above was referred to. Installation Make a note of the command while installing what you need to create the final Dockerfile.
Since Raspberry Pi is ARM, I made it Debian as an image corresponding to ARM. [Reference URL] https://qiita.com/koduki/items/0ed303dac5d32646194f
$ sudo docker run -it -v $(pwd):/tmp/share debian:buster /bin/bash -it: Can be operated in the terminal -v: Folder sharing with containers
Install the required packages depending on the program you want to run.
apt-get install package name
It's like that.
Please note that the "-y" option is required when writing to the Dockerfile because the installation will not be stopped.
In the end, I only needed node and sqlite, so it's better to make the container image a node, By leaving the process, the final result is as follows.
Here's what we're doing: --Copy the code to deploy --Install what you need on the OS --Install the required packages on the node under the deploy folder with "npm install"
#Dockerfile
FROM debian:buster
COPY deploy/ /home/deploy
WORKDIR /home/deploy
RUN apt-get update
RUN apt-get install -y cmake
RUN apt-get install -y libssl-dev
RUN apt install curl
RUN apt-get install -y sqlite3 libsqlite3-dev
RUN apt-get install -y nodejs npm && npm install n -g && n 12.18.4
RUN npm install
Using the Dockerfile created earlier as a container image, the node under the deploy folder will be automatically started in the end.
version: "3.8"
services:
cont:
build:
context: ./cont/env
dockerfile: Dockerfile
container_name: CONT-1
tty: true
volumes:
- "./cont/env/share:/tmp/share"
- ".:/workspace"
- "./cont/env/deploy/build:/home/deploy/build"
working_dir: /home/deploy/build
command: npm run start
"scripts": {
"start": "node ./build/main.js",
},
If you place the created folder environment set in any folder of each OS (Windows 10, Linux, Raspi) and execute the following, all will work in the same way.
sudo docker-compose up --build
[Reference URL] https://tech-lab.sios.jp/archives/21675 https://qiita.com/Yuki_Oshima/items/d3b52c553387685460b0
In Visual Studio Code, click the f1 menu or the green icon that appears at the bottom left, select "Remote-Containers: Open Folder in Container ...", and select the folder containing docker-compose.yml. After a while, the container will run and you can debug it in the console.
vscode, docker convenient ,,
Recommended Posts