A safe directory that can be used in Docker and a development environment

docker hub
docker development environment
docker compose
docker build
dockerfile for development
docker volume
docker development workflow
docker container

I have a webapp which needs to store temporary files wherever it runs. Since I want the app to execute both in Docker and in a development environment - I need a safe directory that can be created in the development environment (Mac OS usually) and in the Docker container.

I used /usr/temp on the container but on a mac this directory in inaccessible.

What would be the best, safest directory to use?

Thank you

If the environment variable $TMPDIR is set, it's a standard place for temporary files, and if it's not set, it usually defaults to /tmp. (On MacOS it points to a per-user directory that quickly gets filled with clutter.) You don't mention what language you're using, but most have a specific function or module to create a file "in the usual temporary directory", which is this one.

In general environment variables are a good way to encapsulate differences between your development and various deployment environments and it makes sense here.

Also remember, on the one hand, that anything in Docker filesystem space you don't explicitly persist will be lost when the container exits, and on the other, that if the container stays running for a long time, there isn't any sort of automated /tmp cleaner. You'll need to properly manage the lifecycle of these files. Also also remember that you have near-complete control over the container's filesystem layout and if you need some specific directory to exist you can RUN mkdir it in your Dockerfile.

Docker development best practices, For instance, you can use the maven image to build your Java application, then in by the build, but only the artifacts and the environment needed to run them. is during development, when you may want to mount your source directory or a  This article describes how you can set up a virtual development environment using Docker. It provides examples on setting up Postgres and PgAdmin4 docker containers and how to use docker compose

Docker provides volumes concept to help you sync up data between Host and Container.

In your case, lets say you want to sync /home/user/data from your host to /usr/temp in Container

you can do so like this

docker run -itd -v /home/user/data:/usr/temp --name mycontainer imagename

Once the container is up and running

Add some file in the data folder and it will be available inside the container in the temp folder and other way around.

Setting Up a Developer Environment Using Docker, But at its very heart, a Linux developer SSHed (secure socket shell) into a computer. Or, I could give myself a Node 6 dev environment running in Docker. I can SSH into this First, create a folder where you'll build your Docker image. Here The resulting committed image will be used for the next step in the Dockerfile. 🕶 Docker based local development environment. Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. Mental model 🧞‍

I ended up having the following in my Dockerfile

RUN mkdir -p $HOME/temp/abc \

And in my configuration files, I used /temp/abc or /temp/xyz to point to the destination folders.

Finally, in my application code I made sure to prepend any path resolution with process.env['HOME'] (NodeJS).

The above works well in both a development envirnment, since $HOME is set by default on a mac and also in production which runs the docker above.

Thanks everyone!

You Don't Need to Rebuild Your Development Docker Image on , You can mount code from your development machine into a container and save yourself tedious waiting times during development. Your development environment however, should be designed to allow for quick iterations instead. If you use bind mounts as shown above to share your project directory with a running  In one file we can define for each service which Docker image will use, port mapping, volumes mapping, environment variables and more. The Dockerfile allows us to create a custom Docker image from

Things I Wish I Knew About Docker Before I Started Using It, What is Docker compose, and why would I want to use it? Next, I set /usr/src/​app as my directory for my WORKDIR. In which case you will want to set up a Docker development environment where you use volumes, and a  For this, you can modify the Docker daemon properties and add DNS settings to that: or you can add a parameter called -dns followed by the DNS server you want the container to use. In some cases you can grab the IP number of the DNS used by the host, in other cases you can use a well known public DNS:

Advanced Container Configuration, See the Developing inside a Container article for additional information. You can set environment variables in your container without altering the container Otherwise run Remote-Containers: Open Folder in Container to connect to the container. You can also use a mount to persist your bash command history across  Docker is available for all modern operating systems. For most users, this will also include Docker Compose. Once installed, keep Docker running in the background to use Docker commands! Dockerfile Example. Your Dockerfile is the blueprint for your container. You’ll want to use your Dockerfile to create your desired environment.

Orchestrating Docker, It is used here to clone the Docker public source code repository. a directory named docker: $ cd docker $ sudo make build This will prepare the development environment and bundles/<version>-dev/binary/ directory. sudo make test If the tests pass, then it is safe to replace [17] Chapter 1 Building Docker from source. Building a local development environment which mirrors production hasn't, historically, been an easy task. But with Docker, it's become, virtually, trivial. Come learn how to setup a local development environment using Docker for developing Zend Expressive (and other PHP) applications.

  • Use a volume for that.
  • Thanks, MyTwoCents but this is not exactly what I meant - bad wording on my side. What I meant is that I want to find a path which I can safely create on both the Docker container and the development machines - which are Macs. Looks like I'll have to use $HOME and make sure to create a directory on both the docker and the dev machines