1

I am pretty relatively new to Docker but I absolutely love how it is designed. I am about to change our project release workflow and I have some questions and I hope some people could share some experiences on what is the best way to go about this.

We use Vagrant to manage development environments. We use a PHP based framework for our projects. My goal is to mimic the live environment on the developer machines as close as possible.

As far as I tried Docker. I could use a CI to create the final container once tests are done that is pushed to our own Docker Hub before release and the server could just fetch the new version of the Container and we can do painless releases. This part is pretty clear for me. This way the source code of a given release is baked into the container.

Although my question is that I do not want the developers to commit Docker images while developing the project. I want them to use Git and use Vagrant and Docker to build the environment locally.

In this case I must have the project source code as a volume ( not part of the container ) to make sure the developers can see real-time edits, debugging etc.

Is there an easy way to achieve this ? Do I need to perhaps use 2 Docker files one Docker file for development environment and one for live release in which the difference is how the source code is managed ?

Any ideas or feedback is appreciated. The key challenge for me is to have a development environment where source code edits and debug is very easy while having the possibility that I can create a final container image containing everything for the shippable software from my CI.

Thanks anyone in advance.

Istvano
  • 992
  • 1
  • 12
  • 19
  • this reads more like discussion, not sure what specific issue – Caffeinated Mar 10 '15 at 21:47
  • 1
    Question is if there is a Docker feature that I am missing to achieve this ? I need the source code of our project to be outside of the container while in development mode and I need to bake it into the container before release. – Istvano Mar 10 '15 at 21:52

1 Answers1

0

I've been using different scripts and file system flags to a similar effect.

Different scripts: When you're starting a Docker container, you can pass the command to run. The command might be the name of a bash script corresponding to the role you want the container to perform. For example, to start it in the development's role you'd use

docker run -t -i $tag /etc/rc.dev

while the release role is just the default (it's script specified with CMD):

docker run -t -i $tag

File system flags: You can control how your container starts and behaves by placing flag files in an outer folder which you mount with VOLUME. For example, my release hosts have an outer SMTP server, but when container is used for development it has to start it's own SMTP server. To that end I'm putting a flag in the outer filesystem, "/var/your_project/flags/start_postfix", and the container's startup script checks this flag as follows:

if [ -e /var/your_project/flags/start_postfix ]; then
  /etc/init.d/rsyslog start
  /etc/init.d/postfix start
fi

So how would you use these?

One option is to have the SSH keys and other kinds of developer's credentials in the VOLUME-mounted folder on the developer's host. The container startup script will then detect the presence of the SSH keys and switch to the development role, in which it will use the keys to pull the fresh version of your project from Git.

ArtemGr
  • 11,684
  • 3
  • 52
  • 85
  • This is great thanks a lot. But what about source code edits while in development if the source code folder is inside the container how can a developer have easy file-system to test and debug their code changes real-time ? – Istvano Mar 11 '15 at 11:41
  • @Istvano Accessing files in the Docker container is a question you'll find a lot information about. Some would enable the SSH and configure an SFTP access, some would checkout (git pull) into a mounted volume (cf. http://stackoverflow.com/questions/28083920/how-to-mount-a-directory-in-the-docker-container-to-the-host). I'm actually using an rsync daemon inside the container and syncing back and forth from the IDE. There's a whole load of options, it's not very different from working with files on a remote server. – ArtemGr Mar 11 '15 at 12:47