0

I am trying to copy a file from my host (Ubuntu 18.04) to a python container but I am having trouble copying it over. The purpose is to take my specific configuration for my default sound device and transfer it over so I don't have to do it manually later.

I've tried several variations and I am wondering if I am misunderstanding how to copy files over. I've checked the documentation and other various questions people on stackoverflow have asked regarding this like this one:

How to copy file from host to container using Dockerfile

But I get an error when I try the traditional command:

docker-compose build 
...
Step 7/7 : COPY /config/.asoundrc ~/.asoundrc
COPY failed: file not found in build context or excluded by .dockerignore: stat config/.asoundrc: file does not exist

I don't have a docker ignore file in my root directory. My directory looks like this:

dejavu (root name)
-config
--.asoundrc
-docker-compose.yaml
...

To be clear, I want to copy the file config/.asoundrc from my host to the container image, specifically the directory destination as ~/.asoundrc

Here is my dockerfile:

FROM python:3.7
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install \
    gcc nano \
    gdebi alsa-utils usbutils ffmpeg libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 \
    postgresql postgresql-contrib pulseaudio -y
RUN pip install numpy scipy matplotlib pydub pyaudio psycopg2 sounddevice

WORKDIR /code
COPY /config/.asoundrc ~/.asoundrc

Here is the original repo, it's currently being modified from an open source project: https://github.com/datafaust/dejavu

LoF10
  • 1,907
  • 1
  • 23
  • 64

1 Answers1

0

I believe you have two issues in your COPY command:

  1. Your source path starts with a slash, it shouldn't
  2. Your destination path contains a ~, which will not be converted to the home directory, as it does in a shell script.

Try this:

COPY config/.asoundrc /root/.asoundrc

In addition, after reviewing your docker-compose.yml, it is clear that the main problem is there.

Your docker-compose file defines a build context:

services:
  python:
    build:
      context: ./docker/python

Which means this is the directory that all COPY commands are relative to. Since this directory only contains the Dockerfile, and not the requested config/.asoundrc file, the build failed with a clear error.

You should place each Dockerfile in the same directory as the application it builds. So, to fix it:

  • Move the Dockerfile from docker to dejavu.
  • Change the build context in docker-compose.yml from ./docker/python to dejavu (also note, no leading dot needed).
DannyB
  • 12,810
  • 5
  • 55
  • 65
  • No dice, I get the following error: `Step 5/8 : WORKDIR /code ---> Running in 6a454bd62b9d Removing intermediate container 6a454bd62b9d ---> 01e08b2b84b4 Step 6/8 : COPY config/.asoundrc /root/.asoundrc COPY failed: file not found in build context or excluded by .dockerignore: stat config/.asoundrc: file does not exist` Basically the main issue seems to be that the file does not exist which doesn't make sense – LoF10 Feb 11 '21 at 15:05
  • Then your question is missing some detail. The problem probably lies in the build-context definition in your `docker-compose.yml`. Can you share the most minimal docker-compose service definition? – DannyB Feb 11 '21 at 15:11
  • Hey Danny, certainly. I added the link to my github repo where you will see the `docker-compose.yml` and the `dockerfile`. Appreciate the help! – LoF10 Feb 11 '21 at 15:17
  • 1
    Your build context is the problem. I updated the answer. – DannyB Feb 11 '21 at 15:34
  • thanks for the help with this, appreciate it greatly – LoF10 Feb 11 '21 at 15:36