<p>You could try using the <code>--profile</code> option during the build.</p>
<pre><code>version: &quot;3&quot;
services:
  strapi:
    profiles: [&quot;strapi&quot;]
    build:
      context: ./
      dockerfile: strapi/Dockerfile
    container_name: &quot;strapi&quot;
    restart: always
    ports:
      - &quot;3000:3000&quot;

  nuxt:
    build:
      profiles: [&quot;nuxt&quot;]
      context: ./
      dockerfile: nuxt/Dockerfile
    image: nuxt:latest
    container_name: &quot;nuxt&quot;
    restart: always
    ports:
      - &quot;3000:3000&quot;
</code></pre>
<p>Then pass the profile switch during the build:</p>
<p><code>docker compose --profile nuxt build</code></p>
<p>Please refer to the official documentation for more information:</p>
<p><a href="https://docs.docker.com/compose/profiles/" rel="nofollow noreferrer">https://docs.docker.com/compose/profiles/</a></p>

CC BY-SA 4.0
2022-11-05T12:05:24.060Z
2022-11-05T12:07:01.123Z
2022-11-05T12:07:01.123Z
ThatTechGuy
<p>Without needing profiles, you can also target specific named services with docker compose, e.g (all containers on the default bridge network).</p>
<pre><code>$ docker compose up -d strapi-backend
$ docker inspect strapi-backend -f '{{ .NetworkSettings.Networks.bridge.Gateway }}'
172.19.0.1
$ docker compose build --build-arg STRAPI_BACKEND_IP=172.19.0.1 nginx-frontend
$ docker compose up -d nginx-frontend
</code></pre>
<p>I found it tricky to get the build process for my (svelte-kit rather than nuxt) image to access the running strapi container. However my strapi container exposes port 1337 on the host, so I am able to access it in the network gateway IP for the network that my containers are on.</p>

CC BY-SA 4.0
2024-08-07T16:31:11.930Z
2024-08-07T16:31:11.930Z
user2863715
<p>This is the step :</p>
<pre><code>  docker compose up Nuxt 3 --build   
  docker compose up Strapi --build
</code></pre>
<p>To update the single service ( profile ). mention the service while using docker compose cmd</p>

CC BY-SA 4.0
2024-08-14T09:35:59.950Z
2024-08-29T12:35:44.917Z
2024-08-29T12:35:44.917Z
playwithcode
<p>I'm trying to build a Nuxt 3 application using docker compose. However, I'm having trouble with docker compose and dockerfile configuration.</p>
<h2>Context</h2>
<p>To give background on the project that I'm working on, here are the stack that I'm using:</p>
<ul>
<li><strong>Nuxt 3</strong> for SSG</li>
<li><strong>Strapi</strong> for CMS</li>
<li><strong>Nginx</strong> for serving static contents generated from Nuxt 3</li>
</ul>
<p>So, in Nuxt 3 I can run <code>npx nuxi generate</code> to pre-render/generate static contents for the website. After generating the static HTML files, nginx will serve the static contents. Strapi will serve as headless CMS, providing contents for the website.</p>
<h2>Problem</h2>
<p>The problem is that, when pre-rendering a static contents in Nuxt 3, it requires Strapi backend to run so that it can fetch the contents from Strapi CMS and generate the html files.</p>
<p>So in terms of command line, I need to make sure that Strapi server is running (<code>strapi start</code>) and only then generate the static files (<code>npx nuxi generate</code>) or else there would be an error during build process because Nuxt application cannot fetch resource from the strapi server.</p>
<p>When using docker, I need to make sure that Strapi server container is running while building the Nuxt/node.js image. However, I don't know how I'm supposed to run a container (strapi server) while building an image (Nuxt SSG contents).</p>
<h2>Files</h2>
<p><strong>Dockerfile.client</strong></p>
<pre><code># Nuxt Image
FROM node:16-alpine as build
WORKDIR /app
COPY ./client .
RUN npm install
RUN npm run generate

# Nginx Image
FROM nginx:1.15 as publish
COPY --from=build /app/.output/public/ /usr/share/nginx/html
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
ENTRYPOINT [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]
</code></pre>
<p><strong>Dockerfile.server</strong></p>
<pre><code># Strapi Image
FROM node:16-alpine
# Installing libvips-dev for sharp Compatability
RUN apk update &amp;&amp; apk add  build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./server/package.json ./server/yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g &amp;&amp; yarn install
WORKDIR /opt/app
COPY ./server .
RUN yarn build
EXPOSE 1337
CMD [&quot;yarn&quot;, &quot;start&quot;]
</code></pre>
<p><strong>docker-compose.yml</strong></p>
<p>In <code>docker-compose.yml</code> file, I specified three services (client, server, database) and all of them belong to one network. I made sure that client <code>depends_on</code> server and database.</p>
<hr />
<p>I just started learning docker few days ago and it's my first time doing DevOps so I might be missing the mark... Any help will be appreciated.</p>
<hr />
<p><strong>Edit 1:</strong></p>
<p>I tried separating <code>docker-compose.yml</code> into two:</p>
<ol>
<li><code>docker-compose.yml</code> for strapi server and database service</li>
<li><code>docker-compose.client.yml</code> for Nuxt service</li>
</ol>
<p>I ran <code>docker compose up</code> for running Strapi server first. After Strapi container was running, I tried running <code>docker compose -f docker-compose.client.yml up --build</code> to build Nuxt image and hoping it would refer to the running strapi container. Unfortunately, Nuxt image was not referring to the running strapi container.</p>

<docker><docker-compose><dockerfile><nginx><node.js>
Docker Compose: How do you build an image while running another container?
Zerro97
# Docker Compose: How do you build an image while running another container?

(Asked by: username_0 on 2022-11-02)

I'm trying to build a Nuxt 3 application using docker compose. However, I'm having trouble with docker compose and dockerfile configuration.
Context
To give background on the project that I'm working on, here are the stack that I'm using:

Nuxt 3 for SSG
Strapi for CMS
Nginx for serving static contents generated from Nuxt 3

So, in Nuxt 3 I can run npx nuxi generate to pre-render/generate static contents for the website. After generating the static HTML files, nginx will serve the static contents. Strapi will serve as headless CMS, providing contents for the website.
Problem
The problem is that, when pre-rendering a static contents in Nuxt 3, it requires Strapi backend to run so that it can fetch the contents from Strapi CMS and generate the html files.
So in terms of command line, I need to make sure that Strapi server is running (strapi start) and only then generate the static files (npx nuxi generate) or else there would be an error during build process because Nuxt application cannot fetch resource from the strapi server.
When using docker, I need to make sure that Strapi server container is running while building the Nuxt/node.js image. However, I don't know how I'm supposed to run a container (strapi server) while building an image (Nuxt SSG contents).
Files
Dockerfile.client
# Nuxt Image
FROM node:16-alpine as build
WORKDIR /app
COPY ./client .
RUN npm install
RUN npm run generate

# Nginx Image
FROM nginx:1.15 as publish
COPY --from=build /app/.output/public/ /usr/share/nginx/html
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Dockerfile.server
# Strapi Image
FROM node:16-alpine
# Installing libvips-dev for sharp Compatability
RUN apk update && apk add  build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./server/package.json ./server/yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
WORKDIR /opt/app
COPY ./server .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "start"]

docker-compose.yml
In docker-compose.yml file, I specified three services (client, server, database) and all of them belong to one network. I made sure that client depends_on server and database.

I just started learning docker few days ago and it's my first time doing DevOps so I might be missing the mark... Any help will be appreciated.

Edit 1:
I tried separating docker-compose.yml into two:

docker-compose.yml for strapi server and database service
docker-compose.client.yml for Nuxt service

I ran docker compose up for running Strapi server first. After Strapi container was running, I tried running docker compose -f docker-compose.client.yml up --build to build Nuxt image and hoping it would refer to the running strapi container. Unfortunately, Nuxt image was not referring to the running strapi container.

**Tags:** docker, docker-compose, dockerfile, nginx, node.js


---

## 3 answers

### Answer by username_1 on 2022-11-05. Score: 1

You could try using the --profile option during the build.
version: "3"
services:
  strapi:
    profiles: ["strapi"]
    build:
      context: ./
      dockerfile: strapi/Dockerfile
    container_name: "strapi"
    restart: always
    ports:
      - "3000:3000"

  nuxt:
    build:
      profiles: ["nuxt"]
      context: ./
      dockerfile: nuxt/Dockerfile
    image: nuxt:latest
    container_name: "nuxt"
    restart: always
    ports:
      - "3000:3000"

Then pass the profile switch during the build:
docker compose --profile nuxt build
Please refer to the official documentation for more information:
https://docs.docker.com/compose/profiles/


---

### Answer by username_2 on 2024-08-07. Score: 0

Without needing profiles, you can also target specific named services with docker compose, e.g (all containers on the default bridge network).
$ docker compose up -d strapi-backend
$ docker inspect strapi-backend -f '{{ .NetworkSettings.Networks.bridge.Gateway }}'
172.19.0.1
$ docker compose build --build-arg STRAPI_BACKEND_IP=172.19.0.1 nginx-frontend
$ docker compose up -d nginx-frontend

I found it tricky to get the build process for my (svelte-kit rather than nuxt) image to access the running strapi container. However my strapi container exposes port 1337 on the host, so I am able to access it in the network gateway IP for the network that my containers are on.


---

### Answer by username_3 on 2024-08-14. Score: 0

This is the step :
  docker compose up Nuxt 3 --build   
  docker compose up Strapi --build

To update the single service ( profile ). mention the service while using docker compose cmd


---

