一直为FreeBSD下怎么使用docker而发愁,发现竟然也有docker-compose
pkg search compose
docker-compose-1.24.0_4 Define and run multi-container applications with Docker
这个版本据说太老了....没搞定....
安装
sudo pkg install docker-compose
需要安装很多依赖库
New packages to be INSTALLED:
docker-compose: 1.24.0_4 [ustc]
libsodium: 1.0.19 [ustc]
libyaml: 0.2.5 [ustc]
py311-async_generator: 1.10_1 [ustc]
py311-async_timeout: 4.0.3_1 [ustc]
py311-attrs: 25.3.0 [ustc]
py311-bcrypt: 4.3.0_2 [ustc]
py311-cached-property: 1.5.2_1 [ustc]
py311-certifi: 2025.8.3 [ustc]
py311-cffi: 1.17.1 [ustc]
py311-charset-normalizer: 3.4.3 [ustc]
py311-colorama: 0.4.6 [ustc]
py311-cryptography: 44.0.3_3,1 [ustc]
py311-curio: 1.6_1 [ustc]
py311-docker: 7.1.0 [ustc]
py311-docker-pycreds: 0.4.0_1 [ustc]
py311-dockerpty: 0.4.1_2 [ustc]
py311-docopt: 0.6.2_2 [ustc]
py311-idna: 3.10 [ustc]
py311-jsonschema: 4.25.1 [ustc]
py311-jsonschema-specifications: 2025.4.1 [ustc]
py311-outcome: 1.3.0_2 [ustc]
py311-paramiko: 3.5.1 [ustc]
py311-pyasn1: 0.6.0 [ustc]
py311-pycparser: 2.22 [ustc]
py311-pynacl: 1.5.0_2 [ustc]
py311-pysocks: 1.7.1_1 [ustc]
py311-python-socks: 2.7.2 [ustc]
py311-pyyaml: 6.0.1_1 [ustc]
py311-referencing: 0.36.2 [ustc]
py311-requests: 2.32.5 [ustc]
py311-rpds-py: 0.27.1 [ustc]
py311-sniffio: 1.3.1 [ustc]
py311-sortedcontainers: 2.4.0_1 [ustc]
py311-texttable: 1.7.0_1 [ustc]
py311-trio: 0.31.0 [ustc]
py311-typing-extensions: 4.15.0 [ustc]
py311-urllib3: 1.26.20,1 [ustc]
py311-websocket-client: 1.8.0 [ustc]
py311-wheel: 0.45.1 [ustc]
Number of packages to be installed: 40
The process will require 39 MiB more space.
7 MiB to be downloaded.
安装之后输出很多提示信息
Message from py311-urllib3-1.26.20,1:
--
Since version 1.25 HTTPS connections are now verified by default which is done
via "cert_reqs = 'CERT_REQUIRED'". While certificate verification can be
disabled via "cert_reqs = 'CERT_NONE'", it's highly recommended to leave it on.
Various consumers of net/py-urllib3 already have implemented routines that
either explicitly enable or disable HTTPS certificate verification (e.g. via
configuration settings, CLI arguments, etc.).
Yet it may happen that there are still some consumers which don't explicitly
enable/disable certificate verification for HTTPS connections which could then
lead to errors (as is often the case with self-signed certificates).
In case of an error one should try first to temporarily disable certificate
verification of the problematic urllib3 consumer to see if that approach will
remedy the issue.
=====
Message from py311-dockerpty-0.4.1_2:
--
===> NOTICE:
The py311-dockerpty port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:
https://bugs.freebsd.org/bugzilla
More information about port maintainership is available at:
https://docs.freebsd.org/en/articles/contributing/#ports-contributing
=====
Message from docker-compose-1.24.0_4:
--
===> NOTICE:
The docker-compose port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:
https://bugs.freebsd.org/bugzilla
More information about port maintainership is available at:
运行
创建文件
创建一个测试目录mkdir testdocker
cd testdocker目录
创建app.py文件
python
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return f'Hello World! I have been seen {count} times.\n'
创建一个文件requirements.txt
python
flask
redis
创建文件Dockerfile
python
# syntax=docker/dockerfile:1
FROM python:3.10-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run", "--debug"]
定义服务
创建文件compose.yaml (后来知道需要创建成docker-compose.yaml文件名才可以)
python
services:
web:
build: .
ports:
- "8000:5000"
redis:
image: "redis:alpine"
我这边需要文件docker-compose.yaml ,修改文件名字
python
cp compose.yaml docker-compose.yaml
编译运行(失败)
python
docker compose up
因为没成功,后面又尝试了使用python3.12的新环境,也是失败。
安装python3.12环境
python
sudo pkg install pyenv
pyenv install miniconda3-3.12-25.7.0-2
忘记了,FreeBSD下不能直接安装miniconda,那就安装3.12版本好了
发现已经pyenv安装了3.12版本,这时候进入bash,写.bashrc文件:
激活
source .bashrc
这时候就是python3.12环境了。
这时候发现docker-compose还是1.24版本,上pypi.org,发现已经好几年没有更新了,看来没法用了。
先放弃这个了。
尝试
尝试一 编译
寻找github源代码:
https://github.com/docker/compose/releases
以后再去做。
尝试二Vagrant 平替
使用vagrant
好像也不行,很多项目是用docker-compose up的,vagrant不能平替
尝试三 docker-composer-v2
docker-composer-v2
装上了,但是没有啊
python
pip install docker-composer-v2
看不到有docker-composer-v2
最终放弃
调试
启动报错Can't find a suitable configuration file in this directory or any parent. Are you in the right directory?
skywalk@fb5:~/work/testdocker $ docker-compose up
ERROR:
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml
需要文件docker-compose.yaml ,修改文件名字
python
cp compose.yaml docker-compose.yaml
搞定
启动报错Unsupported config option for services: 'redis'
skywalk@fb5 \~/work/testdocker\]$ docker-compose-3.11 up
ERROR: The Compose file './docker-compose.yaml' is invalid because:
Unsupported config option for services: 'redis'
发现有一个1.25版本,一个3.11版本,
在docker-compose.yaml文件中加入:
```python
version: '3.11'
```
变成新的报错:
### 报错TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'
```python
docker-compose-3.11 up
Traceback (most recent call last):
File "/usr/local/bin/docker-compose-3.11", line 33, in