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 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]$ ```

相关推荐
java_logo3 小时前
OpenCode 企业级 Docker 部署完整指南
运维·docker·容器·opencode·opencode本地化部署·opencode部署手册·opencode部署方案
再战300年3 小时前
docker下创建redis集群方案
redis·docker·容器
qq_229058015 小时前
docker中检测进程的内存使用量
java·docker·容器
java_logo5 小时前
使用 Docker 部署 Clawdbot(官方推荐方式)
docker·容器·clawdbot·clawdbot部署·clawdbot部署手册·clawdbot部署文档·docker clawdbot
玉树临风江流儿6 小时前
docker镜像加速器配置步骤
运维·docker·容器
短剑重铸之日7 小时前
《SpringCloud实用版》生产部署:Docker + Kubernetes + GraalVM 原生镜像 完整方案
后端·spring cloud·docker·kubernetes·graalvm
lots洋8 小时前
使用docker-compose安装mysql+redis+nacos
redis·mysql·docker
GHL2842710909 小时前
Docker Desktop 启动报错“Virtualization support not detected“
c++·docker·容器
短剑重铸之日9 小时前
《SpringCloud实用版》 Seata 分布式事务实战:AT / TCC / Saga /XA
后端·spring·spring cloud·seata·分布式事务
susu108301891110 小时前
docker启动kafka
docker·容器·kafka