FreeBSD系统使用docker-compose使用docker容器(没搞定)

一直为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 <module>
    sys.exit(load_entry_point('docker-compose==1.24.0', 'console_scripts', 'docker-compose')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/main.py", line 71, in main
    command()
  File "/usr/local/lib/python3.11/site-packages/compose/cli/main.py", line 124, in perform_command
    project = project_from_options('.', options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/command.py", line 33, in project_from_options
    return get_project(
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/command.py", line 121, in get_project
    client = get_client(
             ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/command.py", line 92, in get_client
    client = docker_client(
             ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/compose/cli/docker_client.py", line 97, in docker_client
    kwargs = kwargs_from_env(environment=environment, ssl_version=tls_version)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'

发现这个还是1.24版本

python 复制代码
docker-compose-3.11 -v
docker-compose version 1.24.0, build 0aa5906
[skywalk@fb5 ~/work/testdocker]$
相关推荐
工业一体机老司机3 小时前
Docker部署工控机采集服务 Compose编排与开机自启
运维·docker·容器
SL_staff7 小时前
JVS-APS的7个刚性约束设计:从无限产能幻觉到可执行排产的工程实践
java·spring cloud·全栈
miaobinfei9 小时前
docker拉取dify镜像,执行docker compose up -d 报错
运维·docker·容器
kobe_OKOK_9 小时前
docker compose命名卷 映射到宿主机的路径
运维·docker·容器
晨陌y14 小时前
Flare自托管导航页教程:Docker部署、多用户、API与公网访问
运维·docker·容器
梅孔立16 小时前
Docker 容器网络不通:Tomcat 无法解析 MySQL、Nginx 无法反代 Tomcat 的生产级排查与治理
网络·docker·tomcat
螺蛳粉 螺蛳粉1 天前
第 05 篇:etcd 深入:Raft 共识、watch 机制与快照备份恢复实战(底座认知 05)
docker·云原生·容器·kubernetes·etcd·分布式存储·kube-apiserver
逃逸线LOF1 天前
Ribbon负载均衡原理(Irule组件、源码分析)
后端·spring cloud·ribbon
PellyKoo1 天前
【docker】cifs卷改smb密码后容器起不来的解决方法
运维·docker·容器
时早玖沐1 天前
放弃 QQ 官方机器人:用 SnowLuma + AstrBot 自建 QQ 机器人
docker·开源·agent