Docker tips and tricks — Deploy your working environment in one step
Let’s imagine you are working with Deep Learning models on Ubuntu 18.04. You have spent some time installing required libraries like Tensorflow, Python, maxnet, Keras or PyTorch etc. Once something went wrong and you can’t access your environment (GCE instance is not available, HD has crashed). Familiar situation, is it? First thing comes to mind is to setup all this stuff once again.
Good news are here. You can use Docker to easily and quickly setup your working environments without any headache with dependencies and host platform features. Just use Docker to pull an image with setup you want to use and start it.
First install Docker
sudo apt update
sudo apt install docker.io
Now we need Docker service to be setup to run at startup
sudo systemctl start dockersudo systemctl enable docker
To verify the installed Docker version number, enter:
docker --version
To run Docker without root permission add your user to group docker
sudo usermod -aG docker ${USER}
To apply changes log out and back in, or type the following:
su — ${USER}
You will need to enter your user’s password to continue.
Confirm that your user is now added to the docker group by typing:
id -nG
Let’s try to deploy some image from Docker Hub. In this article I will use image mxnet/python. Simply pull the image
docker pull mxnet/python
This command will start pulling the image to local machine
Using default tag: latest
latest: Pulling from mxnet/python
0a01a72a686c: Pull complete
...
and run it
docker run -it mxnet/python
You will get a standard Linux prompt
root@977233749bfa:/mxnet#
Check the mxnet library installation:
root@977233749bfa:/mxnet# python3
Python 3.5.2 (default, Oct 8 2019, 13:06:37)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mxnet
>>> mxnet.__version__
'1.6.0'
I can probably want to save some work being done so far in container. You need to commit the changes you make to the container and then run it
Then get the container id using this command:
sudo docker ps -l
Commit changes to the container:
sudo docker commit <container_id> <some_id>/<commit_name>
Then run the container:
sudo docker run -it <some_id>/<commit_name>