Composing React apps with services
The main challenge with the previous section was that you had a user interface service self-contained as a running container. The API service, on the other hand, was off doing its own thing. The next tool that you'll learn how to use is docker-compose. As the name suggests, docker-compose is how you compose larger applications out of smaller services. The next natural step for Barely SMS is to use this Docker tool to make the API service and to control both services as one application.
This time, we'll need two Dockerfile files. You can reuse the Dockerfile from the preceding section—just rename it to Dockerfile.ui. Then, create another Dockerfile that's nearly identical—call it Dockerfile.api and give it the following contents:
FROM node:alpine WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3001 CMD [ "npm", "run", "api" ]
The two differences are the EXPOSE port value and the CMD that is run. This command starts the API server...