ERROR: Service 'redis' failed to build. When building redis image by docker-compose

I’m dockerizing an application which based on nodejs, redis and mysql. I already installed redis server and its running fine, but I’m enable to dockerize all three by using docker-compose.yml

$ docker-compose up --build
Building redis
Step 1/11 : FROM node:alpine
 ---> e079048502ec
Step 2/11 : FROM redis:alpine
 ---> da2b86c1900b
Step 3/11 : RUN mkdir -p /usr/src/app
 ---> Using cache
 ---> 28b2f837b54c
Step 4/11 : WORKDIR /usr/src/app
 ---> Using cache
 ---> d1147321eec4
Step 5/11 : RUN apt-get install redis-server
 ---> Running in 2dccd5689663
/bin/sh: apt-get: not found
ERROR: Service 'redis' failed to build: The command '/bin/sh -c apt-get install redis-server' returned a non-zero code: 127

This is my dockerfile.

  • Why doesn´t docker-compose env_file work but environment does?
  • Could not locate Gemfile error by docker compose up
  • Using MySQL with Spring boot docker image
  • git ssh can't access to gitlab in a docker container
  • no route to host between 2 docker containers in same host
  • Programmatically removes files/folder resides in docker container
  • Dockerfile:

    FROM node:alpine
    FROM redis:alpine
    
    # Create app directory
        RUN mkdir -p /usr/src/app
        WORKDIR /usr/src/app
    
    # Install app dependencies
    
        ## Install Redis ##
            RUN apt-get install redis-server
        ## Install nodejs on ubuntu ##
            RUN sudo apt-get update && wget http://nodejs.org/dist/v0.6.9/node-v0.6.9.tar.gz \ 
            && tar -xvzf node-v0.6.9.tar.gz \
            && cd node-v0.6.9 \
            && ./configure && make && sudo make install \
            && mkdir myapp && cd myapp \
            && npm init \
            && npm install express --save \
            && npm install express \
            && npm install --save path serve-favicon morgan cookie-parser body-parser \
            && npm install --save express jade \
            && npm install --save debug \
    
        COPY package.json /usr/src/app/
        COPY redis.conf /usr/local/etc/redis/redis.conf
        RUN npm install
    
    # Bundle app source
        COPY . /usr/src/app
    
    EXPOSE 3000
    
    CMD [ "redis-server", "/usr/local/etc/redis/redis.conf", "npm", "start" ]
    

    This is docker-compose.yml file

    docker-compose.yml

    version: '2'
    
    services:
      db:
        build: ./docker/mysql
        # image: mysql:5.7
        volumes:
          - db_data:/var/lib/mysql
          #- ./mysql:/docker-entrypoint-initdb.d
        # restart: always
        environment:
          MYSQL_ROOT_PASSWORD: root
          # MYSQL_DATABASE: cg_apiserver
          # MYSQL_USER: root
          # MYSQL_PASSWORD: root
    
      redis:
        build: ./docker/redis
        image: "redis:alpine"
    
      node:
        build: ./docker/node
        ports:
          - '3000:80'
        restart: always
        volumes:
           - .:/usr/src/app
        depends_on:
          - db
          - redis
        command: npm start
    
    volumes:
        db_data:
    

  • Run Different Linux OS in Docker Container?
  • Ambari-Server on Docker Java install issues
  • Is it possible to launch a new Docker container from within a running Docker container using Docker Compose?
  • GitLab CI build stuck on pending
  • How do I configure Docker to work with my ens34 network interface (instead of eth0)?
  • Can't run docker commands
  • One Solution collect form web for “ERROR: Service 'redis' failed to build. When building redis image by docker-compose”

    It seems that you have tried to merge two Dockerfile’s in one

    First, your multiple FROM has no sense here. The basic concept is to base FROM only one base image. See this

    Second, you have a docker-compose looking good, but seeing the Dockerfile, it shows that you are trying to build both applications (redis and node app) in the same image.

    So take redis stuff out from ./docker/node/Dockerfile:

    FROM node:alpine
    
    # Create app directory
        RUN mkdir -p /usr/src/app
        WORKDIR /usr/src/app
    
    # Install app dependencies
        ## Install nodejs on ubuntu ##
            RUN wget http://nodejs.org/dist/v0.6.9/node-v0.6.9.tar.gz \ 
            && tar -xvzf node-v0.6.9.tar.gz \
            && cd node-v0.6.9 \
            && ./configure && make && sudo make install \
            && mkdir myapp && cd myapp \
            && npm init \
            && npm install express --save \
            && npm install express \
            && npm install --save path serve-favicon morgan cookie-parser body-parser \
            && npm install --save express jade \
            && npm install --save debug \
    
        COPY package.json /usr/src/app/
        RUN npm install
    
    # Bundle app source
        COPY . /usr/src/app
    
    EXPOSE 3000
    
    CMD ["npm", "start" ]
    

    Use this ./docker/redis/Dockerfile:

    FROM redis:alpine
    COPY redis.conf /usr/local/etc/redis/redis.conf
    # No need to set a custom CMD
    

    And, I recommend to remove the “image:” line from redis (docker-compose.yml). It is not necessary:

     redis:
        build: ./docker/redis
        image: "redis:alpine"        <----
    

    Edit. Also, you don’t need apt-get update anymore. I’ve removed this sudo apt-get update &&

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.