-
Notifications
You must be signed in to change notification settings - Fork 1
Docker tricks
Guilherme Aramizo Ribeiro edited this page Apr 7, 2020
·
4 revisions
Post Install, Give non-root access
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
In new folder, create necessary files and Dockerfile file such as
FROM ubuntu
# the && enforces to always update
# the -y confirms prompt messages
RUN apt-get update && apt-get install -y \
python-pip
# local_file.py must be in the folder
COPY local_file.py /copied_file.py
# CMD defines the standard command in case `docker run` didn't specify
CMD python /copied_file.pyBuild image with
# -t: name tag
docker build -t my_docker_image .First, login your shell with your DockerHub credentials via docker login.
Then tag the image with your username with docker tag <image-id> garamizo/my_docker_image. This will create a copy of the image. To find the <image-id>, call docker image list
Finally, push to cloud with docker push garamizo/my_docker_image.
This is an example of creating a complex container.
First, install NVIDIA driver and enable NVIDIA containers.
The following command install and runs a tensorflow container with
- GPU acceleration
- Jupyter and Python3 support
- Forwarding a port for the browser access
- Loading a volume (folder from host)
- Removing container after exit
docker pull tensorflow/tensorflow:latest-gpu-py3-jupyter
docker run --gpus all \
-u $(id -u):$(id -g) \
--rm \
-p 8888:8888 \
-v $HOME/Documents/MLCourse:/tf/MLCourse \
tensorflow/tensorflow:latest-gpu-py3-jupyterdocker exec -it [container-name] [command]- This can be executed even on containers with
ENTRYPOINT. - However, you need to specify the command even if
DockerfilehasCMD.
docker start [container-name]- This is useful when the image lacks a dependency. You can manually solve the dependency, then restart the container.
- Using this command, the
ENTRYPOINTorCMDis executed in the background.
Give access to devices (cam, serial port, etc) and is within the host network:
sudo docker run -it --privileged --net=host osrf/ros:kinetic-desktop-full bash