Docker pada Linux/macOS
Dalam panduan ini, anda akan menggunakan MyEMS dengan Docker pada Linux (atau macOS).
Prasyarat
- Telah memasang docker, npm pada hos.
- Telah memasang pelayan MySQL.
- Pangkalan data MySQL boleh disambungkan dari hos di mana Docker Engine dijalankan.
- Keperluan perkakasan: Sekurang-kurangnya 4GB RAM, 20GB ruang storan (pangkalan data dan kontena Docker).
Klon kod sumber:
cd ~
git clone https://github.com/myems/myems
Step 1 Database
Lihat Pangkalan Data
Step 2 myems-api
Dalam bahagian ini, anda akan memasang myems-api pada Docker.
- Salin kod sumber ke direktori root
cp -r myems/myems-api /
cd /myems-api
- Buat fail .env berdasarkan fail example.env
Gantikan secara manual 127.0.0.1 dengan alamat IP HOST sebenar.
cp example.env .env
- Bina Imej daripada Kod Sumber
docker build -t myems/myems-api .
Untuk membina untuk pelbagai platform dan bukan hanya untuk seni bina dan sistem pengendalian yang digunakan oleh pengguna yang menjalankan binaan. Anda boleh menggunakan buildx dan tetapkan flag --platform untuk menentukan platform sasaran untuk output binaan, (contohnya, linux/amd64, linux/arm64, atau darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-api .
- Jalankan kontena Docker
Pada hos, buat folder perkongsian fail muat naik:
mkdir /myems-upload
Buat kontena, bind-mount folder perkongsian ke kontena, dan juga bind-mount .env ke kontena:
docker run -d -p 8000:8000 -v /myems-upload:/var/www/myems-admin/upload -v /myems-api/.env:/app/.env:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-api myems/myems-api
-
-d Run container in background and print container ID
-
-p Publish a container's port(s) to the host, 8000:8000 (Host:Container) binds port 8000 (right) of the container to TCP port 8000 (left) of the host machine.
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
The absolute path before colon is for path on host and that may vary on your system. The absolute path after colon is for path on container and that CANNOT be changed. By passing .env as bind-mount parameter, you can change the configuration values later. If you changed .env file, restart the container to make the change effective.
Jika anda ingin memindahkan imej ke komputer lain,
- Eksport imej ke fail tar
docker save --output myems-api.tar myems/myems-api
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-api.tar
Step 3 myems-admin
Dalam bahagian ini, anda akan memasang myems-admin pada Docker.
- Salin kod sumber ke direktori root
cp -r myems/myems-admin /
cd /myems-admin
Gantikan secara manual 127.0.0.1:8000 dalam nginx.conf dengan alamat IP HOST sebenar dan port myems-api
nano nginx.conf
proxy_pass http://127.0.0.1:8000/;
- Bina Imej daripada Kod Sumber
docker build -t myems/myems-admin .
To build for multiple platforms and not only for the architecture and operating system that the user invoking the build happens to run. You can use buildx and set the --platform flag to specify the target platform for the build output, (for example, linux/amd64, linux/arm64, or darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-admin .
- Jalankan kontena Docker
Pada hos, buat folder perkongsian fail muat naik:
mkdir /myems-upload
Buat kontena, bind-mount folder perkongsian fail muat naik ke kontena dan juga bind-mount nginx.conf
docker run -d -p 8001:8001 -v /myems-upload:/var/www/myems-admin/upload -v /myems-admin/nginx.conf:/etc/nginx/nginx.conf:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-admin myems/myems-admin
-
-d Run container in background and print container ID
-
-p Publish a container's port(s) to the host, 8001:8001 (Host:Container) binds port 8001 (right) of the container to TCP port 8001 (left) of the host machine.
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
Jika anda ingin memindahkan imej ke komputer lain,
- Eksport imej ke fail tar
docker save --output myems-admin.tar myems/myems-admin
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-admin.tar
Step 4 myems-modbus-tcp
In this section, you will install myems-modbus-tcp on Docker.
- Copy source code to root directory
cp -r myems/myems-modbus-tcp /
cd /myems-modbus-tcp
- Create .env file based on example.env file
Manually replace 127.0.0.1 with real HOST IP address.
cp example.env .env
- Build Image from Source Code
docker build -t myems/myems-modbus-tcp .
To build for multiple platforms and not only for the architecture and operating system that the user invoking the build happens to run. You can use buildx and set the --platform flag to specify the target platform for the build output, (for example, linux/amd64, linux/arm64, or darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-modbus-tcp .
- Run a Docker container (run as superuser)
docker run -d -v /myems-modbus-tcp/.env:/app/.env:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-modbus-tcp myems/myems-modbus-tcp
-
-d Run container in background and print container ID
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
The absolute path before colon is for path on host and that may vary on your system. The absolute path after colon is for path on container and that CANNOT be changed. By passing .env as bind-mount parameter, you can change the configuration values later.
Jika anda menukar fail .env, mulakan semula kontena untuk menjadikan perubahan berkuat kuasa.
- Pindahkan kontena Docker
Untuk memindahkan kontena ke komputer lain,
- Eksport imej ke fail tar
docker save --output myems-modbus-tcp.tar myems/myems-modbus-tcp
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-modbus-tcp.tar
Step 5 myems-cleaning
Dalam bahagian ini, anda akan memasang myems-cleaning pada Docker.
- Salin kod sumber ke direktori root
cp -r myems/myems-cleaning /
cd /myems-cleaning
- Buat fail .env berdasarkan fail example.env
Gantikan secara manual 127.0.0.1 dengan alamat IP HOST sebenar.
cp example.env .env
- Bina Imej daripada Kod Sumber
docker build -t myems/myems-cleaning .
Untuk membina untuk pelbagai platform dan bukan hanya untuk seni bina dan sistem pengendalian yang digunakan oleh pengguna yang menjalankan binaan. Anda boleh menggunakan buildx dan tetapkan flag --platform untuk menentukan platform sasaran untuk output binaan, (contohnya, linux/amd64, linux/arm64, atau darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-cleaning .
- Jalankan kontena Docker (jalankan sebagai superuser)
docker run -d -v /myems-cleaning/.env:/app/.env:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-cleaning myems/myems-cleaning
-
-d Run container in background and print container ID
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
Laluan mutlak sebelum titik dua adalah untuk laluan pada hos dan mungkin berbeza pada sistem anda. Laluan mutlak selepas titik dua adalah untuk laluan pada kontena dan TIDAK BOLEH diubah. Dengan meletakkan .env sebagai parameter bind-mount, anda boleh menukar nilai konfigurasi kemudian. Jika anda menukar fail .env, mulakan semula kontena untuk menjadikan perubahan berkuat kuasa.
- Pindahkan kontena Docker
Untuk memindahkan kontena ke komputer lain,
- Eksport imej ke fail tar
docker save --output myems-cleaning.tar myems/myems-cleaning
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-cleaning.tar
Step 6 myems-normalization
Dalam bahagian ini, anda akan memasang myems-normalization pada Docker.
- Salin kod sumber ke direktori root
cp -r myems/myems-normalization /
cd /myems-normalization
- Buat fail .env berdasarkan fail example.env
Gantikan secara manual 127.0.0.1 dengan alamat IP HOST sebenar.
cp example.env .env
- Bina Imej daripada Kod Sumber
docker build -t myems/myems-normalization .
Untuk membina untuk pelbagai platform dan bukan hanya untuk seni bina dan sistem pengendalian yang digunakan oleh pengguna yang menjalankan binaan. Anda boleh menggunakan buildx dan tetapkan flag --platform untuk menentukan platform sasaran untuk output binaan, (contohnya, linux/amd64, linux/arm64, atau darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-normalization .
- Jalankan kontena Docker (jalankan sebagai superuser)
docker run -d -v /myems-normalization/.env:/app/.env:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-normalization myems/myems-normalization
-
-d Run container in background and print container ID
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
Laluan mutlak sebelum titik dua adalah untuk laluan pada hos dan mungkin berbeza pada sistem anda. Laluan mutlak selepas titik dua adalah untuk laluan pada kontena dan TIDAK BOLEH diubah. Dengan meletakkan .env sebagai parameter bind-mount, anda boleh menukar nilai konfigurasi kemudian. Jika anda menukar fail .env, mulakan semula kontena untuk menjadikan perubahan berkuat kuasa.
- Pindahkan kontena Docker
Untuk memindahkan kontena ke komputer lain,
- Eksport imej ke fail tar
docker save --output myems-normalization.tar myems/myems-normalization
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-normalization.tar
Step 7 myems-aggregation
Dalam bahagian ini, anda akan memasang myems-aggregation pada Docker.
- Salin kod sumber ke direktori root
cp -r myems/myems-aggregation /
cd /myems-aggregation
- Buat fail .env berdasarkan fail example.env
cp example.env .env
Gantikan secara manual 127.0.0.1 dengan alamat IP HOST sebenar.
- Bina Imej daripada Kod Sumber
docker build -t myems/myems-aggregation .
Untuk membina untuk pelbagai platform dan bukan hanya untuk seni bina dan sistem pengendalian yang digunakan oleh pengguna yang menjalankan binaan. Anda boleh menggunakan buildx dan tetapkan flag --platform untuk menentukan platform sasaran untuk output binaan, (contohnya, linux/amd64, linux/arm64, atau darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-aggregation .
- Jalankan kontena Docker (jalankan sebagai superuser)
docker run -d -v /myems-aggregation/.env:/app/.env:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-aggregation myems/myems-aggregation
-
-d Run container in background and print container ID
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
Laluan mutlak sebelum titik dua adalah untuk laluan pada hos dan mungkin berbeza pada sistem anda. Laluan mutlak selepas titik dua adalah untuk laluan pada kontena dan TIDAK BOLEH diubah. Dengan meletakkan .env sebagai parameter bind-mount, anda boleh menukar nilai konfigurasi kemudian. Jika anda menukar fail .env, mulakan semula kontena untuk menjadikan perubahan berkuat kuasa.
-
Pindahkan kontena Docker
-
Eksport imej ke fail tar
docker save --output myems-aggregation.tar myems/myems-aggregation
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-aggregation.tar
Step 8 myems-web
Dalam bahagian ini, anda akan memasang myems-web pada Docker.
- Ubah fail config.js:
Dapatkan mapboxToken di https://mapbox.com dan kemudian tetapkan showOnlineMap kepada true. Jika anda ingin mematikan ciri peta dalam talian, tetapkan showOnlineMap kepada false
cd myems/myems-web
nano src/config.js
- Ubah fail nginx.conf:
Gantikan 127.0.0.1:8000 dalam nginx.conf dengan ip HOST sebenar dan port myems-api
cd myems/myems-web
nano nginx.conf
- Salin kod sumber ke direktori root
cp -r myems/myems-web /
cd /myems-web
Anda boleh abaikan arahan 'npm run build' dalam bahagian ini, kerana ia telah dibina dalam Dockerfile
- Bina Imej daripada Kod Sumber
docker build -t myems/myems-web .
docker image prune -f
To build for multiple platforms and not only for the architecture and operating system that the user invoking the build happens to run. You can use buildx and set the --platform flag to specify the target platform for the build output, (for example, linux/amd64, linux/arm64, or darwin/amd64).
docker buildx build --platform=linux/amd64 -t myems/myems-web .
docker image prune -f
- Jalankan kontena Docker
Pada hos, bind-mount nginx.conf
docker run -d -p 80:80 -v /myems-web/nginx.conf:/etc/nginx/nginx.conf:ro --log-opt max-size=1m --log-opt max-file=2 --restart always --name myems-web myems/myems-web
-
-d Run container in background and print container ID
-
-p Publish a container's port(s) to the host, 80:80 (Host:Container) binds port 80 (right) of the container to TCP port 80 (left) of the host machine.
-
-v If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory. The ro option, if present, causes the bind mount to be mounted into the container as read-only. For v4.7.0 or earlier versions, use '/code/.env' instead of '/app/.env'.
-
--log-opt max-size=2m The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g).
-
--log-opt max-file=2 The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer.
-
--restart Restart policy to apply when a container exits
-
--name Assign a name to the container
Jika anda ingin memindahkan imej ke komputer lain,
- Eksport imej ke fail tar
docker save --output myems-web.tar myems/myems-web
- Salin fail tar ke komputer lain, kemudian muatkan imej dari fail tar
docker load --input .\myems-web.tar
Selepas pemasangan
Tahniah! Anda kini boleh log masuk ke MyEMS Admin UI dan Web UI.
Port Lalai
MyEMS Web UI: 80
MyEMS API: 8000
MyEMS Admin UI: 8001
Anggap alamat pelayan ialah 192.168.1.8 (gantikan dengan alamat sebenar) Akses MyEMS Web UI di http://192.168.1.8 (80 boleh diabaikan) Akses MyEMS Admin UI di http://192.168.1.8:8001
Kata Laluan Lalai
MyEMS Admin UI
Nama Pengguna:
administrator
Kata Laluan:
!MyEMS1
MyEMS Web UI
Nama Pengguna:
administrator@myems.io
Kata Laluan:
!MyEMS1
Troubleshooting
Due to ISP network issues, you may experience slow image pulling. You can use third-party acceleration services.