The use case
Prepare a project specific development environment that can be fast and easily installed on developer machines. I'm using a docker image for this since it can not only provide the IDE but also the complete tool development chain such as JDKs and build tools like ant or gradle.Terms
First of all its important to understand the difference between containers and images.- image
- Think of an image as a template for creating containers. It contains a filesystem and some definitions (e.g. maintainer and the ports to export etc.). An image can be based on another image and can itself be the basis for other images.
- container
- A container is an instance of an image. Running an image creates a new container based on that image.
Dockerhub
Search Dockerhub for an image that can be used as a base for the container.Pull the image from dockerhub
sudo docker pull joemat/docker-eclipse-for-rcp
This step is optional: When calling docker run with an image that isn't available locally the image is pulled automatically.
Create and run a container based on this image
xhost +local; sudo docker run --name eclipse_luna -it -v /home/joemat/development:/share/development -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix joemat/docker-eclipse-for-rcp
- The
--nameparameter assigns a name to the container that can be used to identify it in subsequent commands. - The
xhost +localcommand and the-e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unixparameters are needed to enable the container to create X windows (see Fábio Rehms Blog). -v /home/joemat/development:/share/development"mounts" the local directory/home/joemat/developmentas/share/developmentin the container.- The container is shut down when the application (eclipse) terminates.
These docker commands may be useful at this point:
sudo docker start -i eclipse_luna
Restarts the docker container when it is stopped (e.g. after eclipse terminated)- No need to pass the
-vand-eparameters again.
- No need to pass the
sudo docker exec -ti eclipse_luna /bin/bash
Executes a different application (a shell in this case) in the running container. This could e.g. be used install additional software packages.
Create an image from the current container status
When all configuration and adjustment has been done, it's time to save the current state of the container. This is done using thedocker commit command, which creates an image from a container. (The container should be stopped before running docker commit.)
sudo docker commit -m "eclipse for project foo" eclipse_luna eclipse_for_foo
Share the image
Now it's possible the push the image to the docker hub using thedocker push command. Alternatively you can push it to your local docker repository. (The Howto from Nik van der Ploeg describes the installation of a private registry server.)
Pushing to the local docker registry needs these steps:
sudo docker login http://mydockerregistry.foo.com:8080Login to the docker registry mydockerregistryserver.sudo docker tag eclipse_for_foo http://mydockerregistry.foo.com:8080/eclipse_for_foo eclipse_for_fooTag the local image/prepare it for pushing to registry server.sudo docker push http://mydockerregistry.foo.com:8080/eclipse_for_fooPush the image to registry server.
Pulling the image from the registry server
Now that the image has been pushed to the registry server it can be pulled and run by others users using the docker pull and/or run commands:sudo docker pull http://mydockerregistry.foo.com:8080/eclipse_for_foo
sudo docker run --name eclipse_for_foo -it -v /home/joemat/development:/share/development -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix http://mydockerregistry.foo.com:8080/eclipse_for_fooOnce the user has created the container, (s)he can restart the container with:
sudo docker start -i eclipse_for_foo
Keine Kommentare :
Kommentar veröffentlichen