我有以下Dockerfile用于启动Django服务器:
FROM python:3.7.4-alpine3.10
LABEL maintainer = ******
ENV PYTHONUNBUFFERED 1S
ENV RUNNING_IN_DOCKER True
RUN apk add --update --no-cache build-base postgresql-client exiftool jpeg-dev zlib-dev gettext git openssl
RUN apk add --update --no-cache gcc libc-dev linux-headers postgresql-dev file-dev py-magic libffi-dev libxml2-dev
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /app
WORKDIR /app
CMD sh start_script.sh
和以下docker-compose.yml:
version: '3'
services:
backend:
build: .
restart: always
ports:
- 127.0.0.1:****:****
env_file:
- .env
environment: &app-env
- POSTGRES_HOST=db
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- REDIS_HOST=redis
- REDIS_PORT=${REDIS_PORT}
depends_on: &app-dep
- db
- redis
volumes: &app-vol
- ./app
db:
image: postgres:10-alpine
restart: always
ports:
- ${POSTGRES_PORT}:****
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- ${LOCAL_POSTGRES_DB_DATA}:/var/lib/postgresql/data
redis:
image: redis:5-alpine
command: ["redis-server", "--appendonly", "yes"]
restart: unless-stopped
ports:
- ${REDIS_PORT}:****
volumes:
- ${LOCAL_REDIS_DATA}:/data
当我尝试运行它时,我在docker-compose日志中得到以下输出:
Attaching to api_backend_1, api_redis_1, api_db_1
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-09-25 09:14:20.936 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port ****
db_1 | 2020-09-25 09:14:20.936 UTC [1] LOG: listening on IPv6 address "::", port ****
db_1 | 2020-09-25 09:14:20.945 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-09-25 09:14:20.965 UTC [20] LOG: database system was shut down at 2020-09-25 09:14:10 UTC
db_1 | 2020-09-25 09:14:20.970 UTC [1] LOG: database system is ready to accept connections
redis_1 | 1:C 25 Sep 2020 09:14:20.818 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 25 Sep 2020 09:14:20.818 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 25 Sep 2020 09:14:20.818 # Configuration loaded
redis_1 | 1:M 25 Sep 2020 09:14:20.819 * Running mode=standalone, port=****.
redis_1 | 1:M 25 Sep 2020 09:14:20.819 # Server initialized
redis_1 | 1:M 25 Sep 2020 09:14:20.819 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 25 Sep 2020 09:14:20.819 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 25 Sep 2020 09:14:20.819 * Ready to accept connections
api_backend_1 exited with code 2
api_backend_1 exited with code 2
这是文件结构:
/ git_repository
| - /app
| - requirements.txt
| - Dockerfile
| - docker-compose.yml
| - start_script.sh PERMISSIONS: -rwxrwxr-x 1 ubuntu ubuntu 208 Sep 25 08:11
奇怪的是,我们有另一个服务具有完全相同的,可以正常工作的Dockerfile和结构...
我唯一可能发现的错误是在Dockerfile中,在运行/app
之前将工作目录更改为start_script.sh
,但是将run命令更改为CMD sh ../start_script.sh
并没有改变错误。对我来说,requirements.txt的副本也没有意义,但这与我认为的错误无关
在搜索时,我遇到了this post about line endings,但该修复程序也不适用于我。
我不确定如何从这里继续进行操作,或者如何进一步调试它,是否有人看到问题或我可以尝试的提示?
答案 0 :(得分:0)
根据对我的问题的评论,我使用import debounce from 'lodash.debounce';
export function MyComponent() {
const [text, setText] = useState(null);
// debounced event handler that is only called again
// after its first call after 1 second
const debouncedHandler = useCallback(
debounce((e) => {
let resultText = e.target.value;
setText(resultText);
}, 1000),
[]
);
return (
<div className="App">
<p>{text}</p>
<input onChange={debouncedHandler} />
</div>
);
}
检查了我的容器。事实证明,我确实没有将任何源代码或start_script.sh复制到我的容器中。我对Dockerfile进行了更改以使其正常工作:
docker-compose run backend sh