0
0
Dockerdevops~10 mins

Docker Compose for dev environment - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Docker Compose for dev environment
Write docker-compose.yml
Run 'docker-compose up'
Docker Compose reads config
Create network and volumes
Start containers
Containers run with dev settings
Develop and test
Run 'docker-compose down' to stop
Docker Compose reads the config file, sets up containers with dev settings, and runs them for easy development.
Execution Sample
Docker
version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    environment:
      - NODE_ENV=development
This docker-compose.yml defines a web service that builds from current folder, maps port 3000, mounts current folder for live code updates, and sets NODE_ENV to development.
Process Table
StepActionEvaluationResult
1Read docker-compose.ymlParse YAMLServices: web defined with build, ports, volumes, environment
2Create networkDefault network createdNetwork 'default' ready
3Create volumeMount current folderVolume mount .:/app set for web
4Build imageDockerfile in .Image built for web service
5Start containerRun container with ports and envContainer 'web' running on port 3000 with NODE_ENV=development
6Container runningCode changes synced via volumeLive reload possible during development
7Run 'docker-compose down'Stop and remove containersContainers stopped and network removed
💡 Stopped after 'docker-compose down' command to clean up dev environment
Status Tracker
VariableStartAfter Step 4After Step 5Final
NetworkNonedefault network createddefault network activeremoved after down
VolumeNonevolume mount setvolume activeremoved after down
Container webNoneimage builtcontainer runningcontainer stopped and removed
Key Moments - 3 Insights
Why do we mount the current folder as a volume in the web service?
Mounting the current folder allows live code changes to be reflected inside the container immediately, enabling fast development without rebuilding the image. See execution_table step 3 and 6.
What happens when we run 'docker-compose down'?
'docker-compose down' stops running containers and removes the network and volumes created for the dev environment, cleaning up resources. See execution_table step 7.
Why do we set NODE_ENV=development in environment variables?
Setting NODE_ENV=development tells the app inside the container to run in development mode, enabling features like debugging and live reload. See execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the container actually started?
AStep 3
BStep 4
CStep 5
DStep 6
💡 Hint
Check the 'Action' column for when the container runs with ports and environment.
According to the variable tracker, what is the state of the network after step 5?
ANo network created
BDefault network active
CNetwork removed
DCustom network active
💡 Hint
Look at the 'Network' row under 'After Step 5' in variable_tracker.
If we remove the volume mount from the compose file, what changes in the execution?
ACode changes won't reflect live inside container
BCode changes inside container update live
CContainer will not start
DPorts will not be mapped
💡 Hint
Refer to key_moments about volume mount and live code updates.
Concept Snapshot
Docker Compose for dev environment:
- Define services in docker-compose.yml
- Use volumes to mount code for live updates
- Map ports to access apps
- Set environment variables for dev mode
- Run 'docker-compose up' to start
- Run 'docker-compose down' to stop and clean
Full Transcript
Docker Compose helps developers run multiple containers easily for development. You write a docker-compose.yml file describing your app's services, ports, volumes, and environment variables. When you run 'docker-compose up', it reads this file, creates a network, mounts your code folder inside the container for live updates, builds the image, and starts the container. This setup lets you develop and test your app quickly. When done, 'docker-compose down' stops containers and cleans up resources. This visual trace showed each step from reading the config to running and stopping containers, tracking network, volume, and container states.