You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/boards/portenta-x8/tutorials/custom-container/content.md
+43-16Lines changed: 43 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ When running a container, it uses an isolated filesystem. This custom filesystem
29
29
30
30
## Container File Structure
31
31
32
-
To create our container we need to collect our necessary files. Creating a folder called **hello-world**, then putting the following files in the folder:
32
+
To create our container we need to collect our necessary files. Creating a folder called **x8-custom-test**, the following files needs to be in the folder:
33
33
- docker-build.conf
34
34
- docker-compose.yml
35
35
- Dockerfile
@@ -40,20 +40,20 @@ To create our container we need to collect our necessary files. Creating a folde
40
40
Lets go through what these files contain and do.
41
41
42
42
### docker-buil.conf
43
-
A file containing the minimal "unit test" command to be executed on the container to prove it's working.
43
+
A file containing the minimal "unit test" command to be executed on the container to prove it's working. Our file will make our containers minimal unit test a test of Python3's help commmand.
44
44
45
45
```python
46
46
TEST_CMD="python3 --help"
47
47
```
48
48
49
49
### docker-compose.yml
50
-
This file defines the app name through the factory, permissions and settings for the involved containers.
50
+
This file defines the app name through the factory, permissions and settings for the involved containers. The argument in the image tag will make it so our image file builds locally.
51
51
52
52
```python
53
53
version: '3.6'
54
54
55
55
services:
56
-
python-hello-world:
56
+
x8-custom-test:
57
57
image: blob-opera:latest
58
58
restart: always
59
59
tty: true
@@ -74,8 +74,8 @@ This is used to build the container.
# docker run -it --rm --user "63" python-hello-world:latest
77
+
# docker build --tag "hello-world:latest" .
78
+
# docker run -it --rm --user "63" hello-world:latest
79
79
80
80
FROM python:3-alpine3.15
81
81
@@ -107,7 +107,7 @@ Flask==0.12.3
107
107
```
108
108
109
109
### Source
110
-
Here we will keep source code of the app you want to run in the container or simply a startup script. We will create a file and name it **main.py** in this folder. This script will ?????.
110
+
Here we will keep source code of the app you want to run in the container or simply a startup script. We will create a file and name it **main.py** in this folder. This script will print "Hello World!" in the CLI window.
111
111
112
112
```python
113
113
from flask import Flask
@@ -121,27 +121,54 @@ if __name__ == '__main__':
121
121
app.run(host='0.0.0.0', port=80)
122
122
```
123
123
124
-
## Upload container
124
+
## Uploading the Container Folder
125
125
126
-
Using docker-compose
126
+
First, you have to have set up your board to a factory, as shown in the [Portenta X8 Out of the Box tutorial]().
127
127
128
-
Should be the preferred way of testing app/containers since inside docker-compose.yml you specify a lot of settings that may not be trivial to convert to docker run arguments
128
+
Once this is done, we will push our folder to a repository within the factory. Lets place our folder "x8-custom-test" inside the "containers.git" repository. You can find this repository inside your factory page, if you click on "Source". And then on "container.git", the url of this page will be used in the next command.
129
129
130
+
In bash use the following command, replace the "YOUR_FACTORY" with the name of your factory, to get the container repository, where we will put our folder. The "-m" tag selects the manifest file within the repository. If no manifest name is selected, the default is "default.xml". And the "-b" tag specifies a revision.
We can also run ```repo sync``` to get the latest version of the repository. Put the "x8-custom-test" folder in the repository.
137
+
138
+
### Building and Running the Container
139
+
140
+
After uploading the folder to the repository. Navigate into the "x8-custom-test" folder, that should be located on your board now. This allows us to build our container with a simple command. Using ```docker build``` with --tag will let us give the container a tag so we can easily keep track of what version of the build this is.
141
+
142
+
```python
143
+
docker build --tag "x8-custom-test:latest" .
133
144
```
134
-
docker-compose up --detach
145
+
146
+
Now that it is built we can run it with ```docker run```, finding it with the tag that we chose to give to the build we want to run. Here we will have to enter the user information into the --user tag. This information is found inside the "docker-compose.yml" file.
147
+
148
+
```python
149
+
docker run -it --rm --user "63" x8-custom-test:latest
135
150
```
136
151
137
-
Should start your application and register it as a systemd service that will be persistent
152
+
### Using docker-compose
153
+
138
154
139
-
accross reboots (e.g. at next boot your docker-compose app will be executed automagically)
155
+
A option for testing an app or container is to use "docker-compose". This is helpful when we have a lot of settings in our "docker-compose.yml" file, since we don't have to use those settings in the run argument with this method. First navigate into the container folder.
140
156
157
+
```python
158
+
cd /home/fio/x8-custom-test
141
159
```
160
+
161
+
This docker-compose command will start your application and register it as a systemd service that will presist even when a reboot occurs. So at the next boot your docker-compose app will run automatically.
162
+
163
+
```python
164
+
docker-compose up --detach
165
+
```
166
+
167
+
To stop the docker-compose app from running, use the following command:
168
+
169
+
```python
142
170
docker-compose stop
143
171
```
144
-
This command will stop your docker-compose app from running
0 commit comments