Create Docker Image
This process follows this link . First update apt and install docker.io
$ sudo apt-get update
$ sudo apt install docker.io
Next start the service and enable it at boot time:
$ sudo systemctl start docker
$ sudo systemctl enable docker
Finally add your current user to the docker group:
$ sudo usermod -a -G docker $USER
and log out of your account and back in.
Create Dockerfile
Create a blank Dockerfile
$ touch Dockerfile
and then edit it to look like the following:
# start with ubuntu
FROM ubuntu:16.04
# update the software repository
RUN apt-get update
RUN apt-get install -y python3-dev
# add user appuser and switch to it
RUN useradd -ms /bin/bash appuser
USER appuser
WORKDIR /home/appuser
# copy over a test message and python
# script to print it to the screen
COPY data/ ./data/
COPY print_message.py .
# run the script at container startup
CMD ["python3", "print_message.py"]
Next make a directory to share with the image and put a simple message file into it.
$ mkdir data
$ echo "Hello from docker" > data/message.txt
Then create a python script to print the message:
if __name__ == '__main__':
with open('data/message.txt') as f:
data = f.read()
print( data )
Build the image and run it:
$ docker build -t test_image
$ docker run -it test_image
Hello from docker
And that's all there is to it.