http://localhost:포트 번호를 변경하는 방법
4257 단어 docker-composeRails
hello rails 화면을 원하는 포트 번호로 연결
절차
포트 번호 3000으로 연결해보기
docker-compose.ymlversion: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
tty: true
stdin_open: true
command: bash -c "bundle exec rails s -p 3000 -b '0.0.0.0'"
depends_on:
- db
db:
image: mysql:8.0.16
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: app_development
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
security_opt:
- seccomp:unconfined
ports:
- "3306:3306"
DockerfileFROM ruby:2.6.5-stretch
ENV LANG C.UTF-8
ENV APP_ROOT /app
WORKDIR $APP_ROOT
RUN apt-get update && apt-get install -y --no-install-recommends \
curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
vim \
mysql-client \
yarn \
nodejs && \
gem install bundler && \
rm -rf /var/lib/apt/lists/*
COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install
COPY . $APP_ROOT
EXPOSE 3000
부팅docker-compose up --build
컨테이너에 들어가다docker-compose exec app bash
Gemfile 업데이트bundle install
새로운 프로젝트 생성 (sqlite가 아닌 mysql 선택)rails new . -d mysql
컨테이너를 떨어뜨리다docker-compose down
database.yml에서 docker-compose db 컨테이너의 password 설정docker-compose up
=> rails 3000 포트가 시작됩니다
포트 번호 3001로 연결
docker-compose.ymlversion: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3001:3001"
tty: true
stdin_open: true
command: bash -c "bundle exec rails s -p 3001 -b '0.0.0.0'"
depends_on:
- db
db:
image: mysql:8.0.16
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: app_development
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
security_opt:
- seccomp:unconfined
ports:
- "3306:3306"
DockerfileFROM ruby:2.6.5-stretch
ENV LANG C.UTF-8
ENV APP_ROOT /app
WORKDIR $APP_ROOT
RUN apt-get update && apt-get install -y --no-install-recommends \
curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
vim \
mysql-client \
yarn \
nodejs && \
gem install bundler && \
rm -rf /var/lib/apt/lists/*
COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install
COPY . $APP_ROOT
EXPOSE 3001
절차
docker-compose.yml
포트 번호 3000으로 연결해보기
docker-compose.yml
version: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
tty: true
stdin_open: true
command: bash -c "bundle exec rails s -p 3000 -b '0.0.0.0'"
depends_on:
- db
db:
image: mysql:8.0.16
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: app_development
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
security_opt:
- seccomp:unconfined
ports:
- "3306:3306"
Dockerfile
FROM ruby:2.6.5-stretch
ENV LANG C.UTF-8
ENV APP_ROOT /app
WORKDIR $APP_ROOT
RUN apt-get update && apt-get install -y --no-install-recommends \
curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
vim \
mysql-client \
yarn \
nodejs && \
gem install bundler && \
rm -rf /var/lib/apt/lists/*
COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install
COPY . $APP_ROOT
EXPOSE 3000
부팅
docker-compose up --build
컨테이너에 들어가다docker-compose exec app bash
Gemfile 업데이트bundle install
새로운 프로젝트 생성 (sqlite가 아닌 mysql 선택)rails new . -d mysql
컨테이너를 떨어뜨리다docker-compose down
database.yml에서 docker-compose db 컨테이너의 password 설정docker-compose up
=> rails 3000 포트가 시작됩니다
포트 번호 3001로 연결
docker-compose.ymlversion: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3001:3001"
tty: true
stdin_open: true
command: bash -c "bundle exec rails s -p 3001 -b '0.0.0.0'"
depends_on:
- db
db:
image: mysql:8.0.16
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: app_development
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
security_opt:
- seccomp:unconfined
ports:
- "3306:3306"
DockerfileFROM ruby:2.6.5-stretch
ENV LANG C.UTF-8
ENV APP_ROOT /app
WORKDIR $APP_ROOT
RUN apt-get update && apt-get install -y --no-install-recommends \
curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
vim \
mysql-client \
yarn \
nodejs && \
gem install bundler && \
rm -rf /var/lib/apt/lists/*
COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install
COPY . $APP_ROOT
EXPOSE 3001
절차
docker-compose.yml
version: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3001:3001"
tty: true
stdin_open: true
command: bash -c "bundle exec rails s -p 3001 -b '0.0.0.0'"
depends_on:
- db
db:
image: mysql:8.0.16
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: app_development
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
security_opt:
- seccomp:unconfined
ports:
- "3306:3306"
FROM ruby:2.6.5-stretch
ENV LANG C.UTF-8
ENV APP_ROOT /app
WORKDIR $APP_ROOT
RUN apt-get update && apt-get install -y --no-install-recommends \
curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
vim \
mysql-client \
yarn \
nodejs && \
gem install bundler && \
rm -rf /var/lib/apt/lists/*
COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install
COPY . $APP_ROOT
EXPOSE 3001
Dockerfile
http://localhost:3001
에서 rails가 시작됩니다.
Reference
이 문제에 관하여(http://localhost:포트 번호를 변경하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/uechikohei/items/c42524818e85aa6d4ac9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)