Skip to content

Commit a610b5b

Browse files
Added more instructions
1 parent e989a05 commit a610b5b

File tree

1 file changed

+43
-16
lines changed
  • content/hardware/04.pro/boards/portenta-x8/tutorials/custom-container

1 file changed

+43
-16
lines changed

content/hardware/04.pro/boards/portenta-x8/tutorials/custom-container/content.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ When running a container, it uses an isolated filesystem. This custom filesystem
2929

3030
## Container File Structure
3131

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:
3333
- docker-build.conf
3434
- docker-compose.yml
3535
- Dockerfile
@@ -40,20 +40,20 @@ To create our container we need to collect our necessary files. Creating a folde
4040
Lets go through what these files contain and do.
4141

4242
### 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.
4444

4545
```python
4646
TEST_CMD="python3 --help"
4747
```
4848

4949
### 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.
5151

5252
```python
5353
version: '3.6'
5454

5555
services:
56-
python-hello-world:
56+
x8-custom-test:
5757
image: blob-opera:latest
5858
restart: always
5959
tty: true
@@ -74,8 +74,8 @@ This is used to build the container.
7474
#
7575

7676
# Examples:
77-
# docker build --tag "python-hello-world:latest" .
78-
# 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
7979

8080
FROM python:3-alpine3.15
8181

@@ -107,7 +107,7 @@ Flask==0.12.3
107107
```
108108

109109
### 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.
111111

112112
```python
113113
from flask import Flask
@@ -121,27 +121,54 @@ if __name__ == '__main__':
121121
app.run(host='0.0.0.0', port=80)
122122
```
123123

124-
## Upload container
124+
## Uploading the Container Folder
125125

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]().
127127

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.
129129

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.
131+
132+
```python
133+
repo init -u https://source.foundries.io/factories/YOUR_FACTORY/containers.git -m arduino.xml -b devel
130134
```
131-
cd /home/fio/hello-world
132-
```
135+
136+
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" .
133144
```
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
135150
```
136151

137-
Should start your application and register it as a systemd service that will be persistent
152+
### Using docker-compose
153+
138154

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.
140156

157+
```python
158+
cd /home/fio/x8-custom-test
141159
```
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
142170
docker-compose stop
143171
```
144-
This command will stop your docker-compose app from running
145172

146173

147174
## Conclusion

0 commit comments

Comments
 (0)