Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Recompiling takes too long inside docker container #270

@zavvdev

Description

@zavvdev

Hi! I'm playing with Rocket framework and created a monorepository with dockerized server service. I'm using cargo-watch for development mode and it works fine if I launching it locally. After saving source files it recompiles after ~0.68 seconds. But when I start server service inside docker container it takes too long. Near 2 minutes to restart.
Screenshot 2023-05-21 at 7 35 31 PM

This is my docker-compose.yml file:

services:
  client:
    image: ${APP_NAME}_client
    build:
      context: ./client
    container_name: ${APP_NAME}_client
    command: pnpm prod
    restart: unless-stopped
    networks:
      - common

  server:
    image: ${APP_NAME}_server
    build:
      context: ./server
      dockerfile: ./Dockerfile
    container_name: ${APP_NAME}_server
    command: cargo build -r && ROCKET_ENV=production cargo run -r
    restart: unless-stopped
    networks:
      - common

  nginx:
    image: ${APP_NAME}_nginx
    build:
      context: ./nginx
    container_name: ${APP_NAME}_nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf
    depends_on:
      - server
      - client
    networks:
      - common

networks:
  common:
    name: ${APP_NAME}-network
    driver: bridge

docker-compose.dev.yml

version: "3.9"
services:
  client:
    command: pnpm dev
    stdin_open: true
    tty: true
    ports:
      - 3001:3000
    volumes:
      - ./client/src:/usr/src/app/src

  server:
    build:
      context: ./server
      dockerfile: ./Dockerfile.dev
    command: cargo watch -x run
    volumes:
      - ./server/src:/usr/src/app/src
      - ./server/target:/usr/src/app/target

  nginx:
    volumes:
      - ./nginx/nginx.dev.conf:/etc/nginx/conf.d/nginx.conf

And Dockerfile.dev:

FROM rust:1.67
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN cargo install cargo-watch
COPY . .

As you can see, I've added src and target folder into the container volumes. I'm not sure if it's an issue with cargo-watch but it's really not obvious why it behaves like this. It looks like on each save it ignores cache and compiling from scratch. But container contains target folder. Does anyone know what's wrong there? Is this a cargo-watch issue?

You can find full repo here: https://github.com/zavvdev/rocket-svelte-rest/tree/main

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions