将Rails 6应用程序推送到Docker Hub

问题描述 投票:0回答:1

我正在努力使我对Docker有所了解。我将其与Rails 6应用程序一起使用,它成功构建并运行。现在,我想将应用程序推送到我的Docker Hub存储库中。

我不太确定该怎么做,因为我有3个容器,但是在每个教程中,我读到的人都只是推一个。

这是docker ps -a的输出:

enter image description here

这是我的docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    volumes:
      - postgres:/var/lib/postgresql/data
    env_file: 
      - .env
    ports: 
      - "5432"
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
        - .:/webmenue
        - bundler_gems:/bundle
        - ./docker/database.yml:/webmenue/config/database.yml
        - cache:/cache
    ports:
        - "3000:3000"
    env_file:
        - .env
    environment:
      - RAILS_ENV=development
      - WEBPACKER_DEV_SERVER_HOST=webpacker
      - SPROCKETS_CACHE=/cache
    depends_on:
        - db
  webpacker:
    build: .
    command: ./bin/webpack-dev-server
    volumes:
        - .:/webmenue
    ports:
        - '3035:3035'
    environment:
        - NODE_ENV=development
        - RAILS_ENV=development
        - WEBPACKER_DEV_SERVER_HOST=0.0.0.0

volumes:
    postgres:
    bundler_gems:
    cache: 

我读到--link标志,但这似乎已被弃用。因此:我需要推入所有容器,还是有办法将它们放入一个容器中?

ruby-on-rails docker dockerhub
1个回答
0
投票

简而言之很简单:如果您有多张图像,则需要多次按下;)

现在有帮助的答案,您有2张图像:postgresscurrent working directory。 Postgress已经是您从docker hub下载的映像,因此无需推送它。

至于您的其他2个应用程序,它们当前位于一个docker文件中,因此仅需要一次推送。

在您的撰写文件中,它们都使用build: .,因此它们共享docker映像。假设您使用docker push max-kirsch/my-cool-app:1.0.0进行了推送,则将docker compose文件更改为如下所示:

version: '3'
services:
  db:
    image: postgres
    volumes:
      - postgres:/var/lib/postgresql/data
    env_file: 
      - .env
    ports: 
      - "5432"
  web:
    image: max-kirsch/my-cool-app:1.0.0
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
        - .:/webmenue
        - bundler_gems:/bundle
        - ./docker/database.yml:/webmenue/config/database.yml
        - cache:/cache
    ports:
        - "3000:3000"
    env_file:
        - .env
    environment:
      - RAILS_ENV=development
      - WEBPACKER_DEV_SERVER_HOST=webpacker
      - SPROCKETS_CACHE=/cache
    depends_on:
        - db
  webpacker:
    image: max-kirsch/my-cool-app:1.0.0
    command: ./bin/webpack-dev-server
    volumes:
        - .:/webmenue
    ports:
        - '3035:3035'
    environment:
        - NODE_ENV=development
        - RAILS_ENV=development
        - WEBPACKER_DEV_SERVER_HOST=0.0.0.0

volumes:
    postgres:
    bundler_gems:
    cache: 

我认为您很困惑,因为您的撰写文件中有2个共享相同docker文件的应用。可能是这种混淆是正确的。我个人认为,您应该在docker文件中同时创建它们,只安装所需的组件。很难确定没有看到docker文件,但是作为示例,它看起来像Webpacker似乎不需要安装ruby,并且可以以简单的节点映像作为基础开始,而不是在ruby映像中安装节点。

© www.soinside.com 2019 - 2024. All rights reserved.