Docker + Next.js + Remote-Containers
.devcontainer/devcontainer.json
{
"name": "myapp-backend",
"dockerComposeFile": "../docker-compose.yml",
"service": "api",
"workspaceFolder": "/",
"initializeCommand": "ssh-add ~/.ssh/id_rsa"
}
.devcontainer/Dockerfile
FROM ruby:3.1.2
ARG APP_NAME=myapp-backend
ARG USER_NAME=ruby
ENV RUBYGEMS_VERSION=3.3.10
ENV TZ=Asia/Tokyo
WORKDIR /${APP_NAME}
COPY Gemfile Gemfile.lock /${APP_NAME}
RUN gem update --system ${RUBYGEMS_VERSION} && \
bundle install
COPY /docker/api/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN adduser ${USER_NAME} && \
chown -R ${USER_NAME} /${APP_NAME} && \
chown -R ${USER_NAME} ${GEM_HOME}
USER ${USER_NAME}
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
/docker-compose.yml
version: '3.9'
services:
db:
platform: linux/x86_64
image: mysql:8.0.28
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./src/db/mysql_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
api:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- ./src:/app
ports:
- "3000:3000"
depends_on:
- db