0
votes

I'm probably doing something very wrong, but I'll ask here just in case since I can't find it. Basically, I have no problem running my docker image when I'm on my pc and I just do "Docker-compose run..." from within the ruby app directory. However, when I push the image to the docker-hub, I want to pull that image on my ubuntu server to then build that image. The problem is that when I do so, I don't really have access to the ruby app, the gemfile or anything so it doens't work at all...

This was my error :

Step 10/23 : COPY Gemfile /myapp/Gemfile COPY failed: stat /var/lib/docker/tmp/docker-builder296802662/Gemfile: no such file or directory

My Dockerfile :


RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update -qq && apt-get install -y nodejs yarn netcat libpq-dev nano tzdata apt-transport-https

RUN apt-get clean autoclean
RUN rm -rf /var/lib/apt /var/lib/dpkg /var/lib/cacbe /var/lib/log

RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile Gemfile.lock /myapp/

RUN bundle install

COPY . .

RUN rm -Rf node_modules/
RUN rm yarn.lock
RUN spring stop

RUN rails webpacker:install
RUN yarn install
RUN yarn upgrade
RUN yarn install --check-files

EXPOSE 3000

# Running the startup script before starting the server
ENTRYPOINT ["sh", "./config/docker/startup.sh"]
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]

My docker-compose :

services:
  db:
    image: mysql:latest
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    # volumes:
      # - ./tmp/db:/var/lib/postgresql/data
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test
      MYSQL_USERNAME: root
      MYSQL_PASSWORD: root
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db
    links: 
      - db
    environment: 
      DB_USER: root
      DB_NAME: test
      DB_PASSWORD: root
      DB_HOST: db
      DB_PORT: 3306
      RAILS_ENV: development

How am I supposed to make it so that on my ubuntu server I can simply pull the image from my repo, build and run it?

Thank you very much.

P.S. I also always get "Your Yarn packages are out of date!"...

1

1 Answers

1
votes

If you've pushed your application images to Docker Hub, you need to, all in the web service:

  • Add the image: name of your Docker Hub image
  • Remove the build: section
  • Delete the volumes: that overwrite the image's code
  • Delete the command: overriding the image's CMD (consider adding the rm -f server.pid command to your startup.sh entrypoint script)
  • Delete the archaic links: setting

This leaves you with:

version: '3.8'
services:
  db: *as_in_the_question
  web:
    image: 'myname/web:20200622'
    ports:
      - "3000:3000"
    depends_on:
      - db
    environment: 
      DB_USER: root
      DB_NAME: test
      DB_PASSWORD: root
      DB_HOST: db
      DB_PORT: 3306
      RAILS_ENV: development

On the remote system you need to copy only the docker-compose.yml file, and you should be able to run docker-compose up to start it; it will pull the Docker Hub image and run it.

On the local system, if you have both a build: and an image: setting, docker-compose build will tag the image with the name you specify, and docker-compose push will push the built image.