Home > OS >  Can't install packages in docker container using Dockerfile
Can't install packages in docker container using Dockerfile

Time:02-08

I'd like to install a package in a docker image, via a Dockerfile.

docker-compose.yml:

version: "3.5"
services:
  transmission:
    build:
      context: .
      dockerfile: Dockerfile
    image: ghcr.io/linuxserver/transmission
    container_name: transmission
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - ./config/public:/config
      - /data:/data
    ports:
      - 60020:60020
      - 60010:60010
      - 60010:60010/udp
    restart: unless-stopped
    network_mode: host

Dockerfile:

RUN apk update
RUN apk add --no-cache flac

In the Dockerfile, I specify that I'd like to install the flac package. After that I run docker-compose up -d, and sudo docker exec -it transmission bash to check whether it's present, but it's not.

What am I doing wrong?

CodePudding user response:

Your Dockerfile isn't valid (if you've posted the whole file). You've also specified both build: and image: tags in your docker-compose file which is used when you want to build an image and give it a tag when built.

What I think you're trying to accomplish is to add flac to the transmission image. To do that, you'd create a Dockerfile like this

FROM ghcr.io/linuxserver/transmission
RUN apk update
RUN apk add --no-cache flac

Then in your docker-compose file, you remove the image specification like this

version: "3.5"
services:
  transmission:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: transmission
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - ./config/public:/config
      - /data:/data
    ports:
      - 60020:60020
      - 60010:60010
      - 60010:60010/udp
    restart: unless-stopped
    network_mode: host
  •  Tags:  
  • Related