patterndockerMinor
Developing inside a Docker image?
Viewed 0 times
insideimagedockerdeveloping
Problem
Every time I onboard a new person on my team I have to go through the same routine of installing everything, figuring out what changed since last time we onboarded someone etc. Not fun.
I've heard about people maintaining docker containers with the development environment, but I'm not sure how to accomplish this.
Let's say you work on a repository containing a React webapp. Our IDE of choice is IntelliJ. It'd be cool if a new dev would just get a container with all the necessary dev stuff installed.
How do I make this happen?
I've heard about people maintaining docker containers with the development environment, but I'm not sure how to accomplish this.
Let's say you work on a repository containing a React webapp. Our IDE of choice is IntelliJ. It'd be cool if a new dev would just get a container with all the necessary dev stuff installed.
How do I make this happen?
Solution
The onboarding experience should be almost as simple as telling your new developer to just clone the repo and run
Every project/application (if you have multiple) should be able to run separately and each project/application should have it's own codebase. That's a concept from The Twelve-Factor App methodology.
In the root of each project add a
NOTE: I created Craft Kits which you can use to automatically generate these files for the framework/language you're using with one command (e.g.
The
The
When you onboard a new developer, you can just tell them to
The advantage of this approach when you are developing locally, running
Then when you want to deploy, when you build your
We use the same approach for apps on Codemason, my service for building, managing and scaling container-based applications. When you push new code, we automatically build an image from your Dockerfile. Since that image contains everything your app needs to run, it can be easily launched on any server and scaled up/down across multiple servers.
docker-compose up. Personally I wouldn't bother worrying about IDE integration because people might prefer to use different IDEs.Every project/application (if you have multiple) should be able to run separately and each project/application should have it's own codebase. That's a concept from The Twelve-Factor App methodology.
In the root of each project add a
Dockerfile and a docker-compose.yml file. NOTE: I created Craft Kits which you can use to automatically generate these files for the framework/language you're using with one command (e.g.
mason craft nodejs), you don't even need to know Docker.The
Dockerfile will build your application into an image, installing and dependencies your application needs to run. This image is the image that runs your app.FROM node:8.8-alpine
# Set our workdir
WORKDIR /app
# Install and cache app dependencies
COPY package.json /app
RUN npm install
# Add project files
COPY . /app
# start app
CMD [ "npm", "start" ]The
docker-compose.yml file will spin up your environment. It will define all the services Docker should start for your applicationversion: '2'
services:
web:
build: .
volumes:
- ./:/app
ports:
- "3000:3000"
mongodb:
image: mongodb
volumes:
- ./storage/data/mongodb:/data/db
ports:
- "27017:27017"When you onboard a new developer, you can just tell them to
git clone your repo and to fire up their development environment by running: docker-compose up -dThe advantage of this approach when you are developing locally, running
docker-compose up will mount your code as a volume. Then when you want to deploy, when you build your
Dockerfile it will copy your code into your image so everything is packaged up nicely and easily moved around.We use the same approach for apps on Codemason, my service for building, managing and scaling container-based applications. When you push new code, we automatically build an image from your Dockerfile. Since that image contains everything your app needs to run, it can be easily launched on any server and scaled up/down across multiple servers.
Code Snippets
FROM node:8.8-alpine
# Set our workdir
WORKDIR /app
# Install and cache app dependencies
COPY package.json /app
RUN npm install
# Add project files
COPY . /app
# start app
CMD [ "npm", "start" ]version: '2'
services:
web:
build: .
volumes:
- ./:/app
ports:
- "3000:3000"
mongodb:
image: mongodb
volumes:
- ./storage/data/mongodb:/data/db
ports:
- "27017:27017"docker-compose up -dContext
StackExchange DevOps Q#2546, answer score: 8
Revisions (0)
No revisions yet.