- If 2 people are working on the same project but with 2 different environments, there may be dependency version issues.
- Some packages are optimize for a special OS.
Docker is a manager of container.
Container:
• Isolates app from each other
• Shares the same kernel – kernel shares resources with the host and interacts with the containers
Advantages
• Quicker to launch (no os to boot)
• Portability (less dependencies between processed layers)
• Efficiency
-
Pull an image from Docker hub: docker login then docker pull
-
Check the image: docker images
-
Create a container: docker run –it nom Few options:
INSTRUCTION SIGNIFICATION -i Interactive mode -p Publish a container᾿s port or a range of ports to the host format (-p 8888:4000) -t Allocate a pseudo-tty -v path/to/volume Bind mount a volume -
Stop the container: docker stop id_container nom
-
Interact with a container with shell: docker run –it nom_container /bin/bash
-
Save the container after modification: docker commit id_container nom
-
Stop the container
-
Confirm the container has been stop: docker ps –a
-
Delete the container: docker rm id_container
- Create a directory
- Create your Dockerfile
Commands:
INSTRUCTION | SIGNIFICATION |
---|---|
FROM | Set base image |
LABEL | Add metadata |
COPY | Copy files/directories into the image |
ENV | Set environment variable |
EXPOSE | Informs Docker that the container listens on the specified network ports at runtime |
WORKDIR | Set working directory |
RUN | Execute shell commands in a new layer |
ENTRYPOINT | Configure container to run as executable |
CMD | Provide default for executing container |
Example
- Create hello_world.py: print("Hello world!")
- Build your image: docker build –t nom .
- Create the container: docker run nom
- Upload to docker hub:
- docker login
- docker tag image username/repository:tag (example: docker tag friendlyhello john/first_docker:test)
- docker push username/repository:tag
-
Create a directory
-
Create your Dockerfile in this new directory.
FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3 python3-pip
COPY requirements.txt .
RUN pip3 install jupyter
RUN pip3 install -r requirements.txt
RUN useradd -ms /bin/bash jupyter
USER jupyter
WORKDIR /home/jupyter
COPY hello_world.txt .
ENTRYPOINT ["jupyter", "notebook", "--ip=*"]
-
Create requirements.txt with Tensorflow, Keras.
-
Create hello_world.txt
-
Build your image: docker build -t jupyter .
-
Create a new container: docker run -it -p 8888:8888 jupyter /home
-
Consulte the results on your browser (you might need to change your ip address)