[11] [DFN[[RUBYB[[[UNIXドメインソケット]]]@en[UNIX domain socket]]]]は、
多くの [[UNIX]] 系システムで実装されている [[IPC]] 機構の一種です。

[REFS[
- [15] [CITE[]] ([TIME[2000-01-10 18:36:02 +09:00]] 版) <http://pubs.opengroup.org/onlinepubs/009619199/apdxo.htm>
- [14] [CITE[unix(7) - Linux manual page]] ([TIME[2015-09-09 21:15:22 +09:00]] 版) <http://man7.org/linux/man-pages/man7/unix.7.html>
-- [4] [CITE[Man page of UNIX]]
([TIME[2012-07-10 13:44:11 +09:00]] 版)
<http://linuxjm.sourceforge.jp/html/LDP_man-pages/man7/unix.7.html>
]REFS]

* API

[6] [[Socket]]

* 上位層プロトコル

[1] 様々な[[アプリケーションプロトコル]]の下位層として用いられています。

[10] [[HTTP]] での利用については、 [[HTTP接続]]を参照。

[36] [CITE@en[RFC 1459 - Internet Relay Chat Protocol]], [TIME[2021-04-11T07:15:29.000Z]], [TIME[2021-04-13T03:26:30.637Z]] <https://tools.ietf.org/html/rfc1459#section-8.1.1>

* URL

[35] [CITE@en[Addressing HTTP servers over Unix domain sockets · Issue #577 · whatwg/url · GitHub]], [TIME[2021-02-14T02:25:43.000Z]] <https://github.com/whatwg/url/issues/577>

** [CODE(URI)@en[unix:]]

[5] [[URL scheme]] として [DFN[[CODE(URI)@en[[[unix:]]]]]]
が使われることがあります。

[29] [[PHP]] 3+ が実装しています。


[FIG(quote)[
[FIGCAPTION[
[2] [CITE@en[Docker basics - Docker Documentation]]
([TIME[2015-02-27 00:20:24 +09:00]] 版)
<https://docs.docker.com/articles/basics/>
]FIGCAPTION]

> unix://path/to/socket -> Unix socket located at path/to/socket

]FIG]


[FIG(quote)[
[FIGCAPTION[
[3] [CITE@en[Docker basics - Docker Documentation]]
([TIME[2015-02-27 00:20:24 +09:00]] 版)
<https://docs.docker.com/articles/basics/>
]FIGCAPTION]

> $ sudo <path to>/docker -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -d &

]FIG]

[FIG(quote)[
[FIGCAPTION[
[17] [CITE@en[Infinario/flask-redis-sentinel]]
([TIME[2015-09-18 15:33:39 +09:00]] 版)
<https://github.com/infinario/flask-redis-sentinel>
]FIGCAPTION]

> unix://'''[''':password''']'''@/path/to/socket.sock?db=0

]FIG]

[FIG(quote)[
[FIGCAPTION[
[30] [CITE@en[FFmpeg Protocols Documentation]]
([TIME[2017-01-22 02:22:36 +09:00]])
<https://ffmpeg.org/ffmpeg-protocols.html#unix>
]FIGCAPTION]

> Unix local socket
> The required syntax for a Unix socket URL is:
> unix://filepath

]FIG]

** [CODE(URI)@en[udg:]]

[13] [[PHP]]5以上では [[Unix domain socket]] による[[データグラム]] ([[UDP]] 相当)
を表すために [DFN[[CODE(URI)@en[[[udg:]]]]]] を使っています。

** authority

[33] [[Docker]]
は
[CODE[http://%2Fvar%2Frun%2Fdocker.sock/]] 
のような
[[URL]]
を使っています。

* ホストとポート

[20] 実装によっては、[[ホスト]]を [DFN[[CODE[unix/]]]]、[[ポート]]を[[ファイル名]]とすることで、
[[TCP]] ではなく [[UNIX domain socket]] での接続として扱うことがあります。

* 実装

[FIG(quote)[
[FIGCAPTION[
[7] [CITE@en[Connection String URI Format — MongoDB Manual 2.6.7]]
([TIME[2015-01-24 08:01:19 +09:00]] 版)
<http://docs.mongodb.org/manual/reference/connection-string/>
]FIGCAPTION]

> The following connects to a UNIX domain socket:
> mongodb:///tmp/mongodb-27017.sock

]FIG]

[FIG(quote)[
[FIGCAPTION[
[8] [CITE[Module ngx_http_proxy_module]]
([TIME[2015-02-26 15:57:24 +09:00]] 版)
<http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass>
]FIGCAPTION]

> or as a UNIX-domain socket path specified after the word “unix” and enclosed in colons:
> proxy_pass http://unix:/tmp/backend.socket:/uri/;

]FIG]

[FIG(quote)[
[FIGCAPTION[
[9] [CITE[AnyEvent::Socket - search.cpan.org]]
([TIME[2015-03-21 20:30:43 +09:00]] 版)
<http://search.cpan.org/dist/AnyEvent/lib/AnyEvent/Socket.pm#($service,_$host)_=_AnyEvent::Socket::unpack_sockaddr_$sa>
]FIGCAPTION]

> If the $text is unix/, then this function returns a special token recognised by the other functions in this module to mean "UNIX domain socket".

]FIG]


[FIG(quote)[
[FIGCAPTION[
[12] [CITE@en[kennethreitz/dj-database-url]]
([TIME[2015-07-09 00:48:26 +09:00]] 版)
<https://github.com/kennethreitz/dj-database-url>
]FIGCAPTION]

> With PostgreSQL, you can also use unix domain socket paths with percent encoding: postgres://%2Fvar%2Flib%2Fpostgresql/dbname.

]FIG]

[FIG(quote)[
[FIGCAPTION[
[16] [CITE[Using Redis — Celery 3.1.18 documentation]]
([TIME[2015-09-10 03:56:21 +09:00]] 版)
<http://celery.readthedocs.org/en/latest/getting-started/brokers/redis.html>
]FIGCAPTION]

> If a unix socket connection should be used, the URL needs to be in the format:
> redis+socket:///path/to/redis.sock

]FIG]


[18] [CITE[Issue 376323002: Refactor unix domain socket. - Code Review]]
([TIME[2015-09-22 18:14:15 +09:00]] 版)
<https://codereview.chromium.org/376323002/>

[FIG(quote)[
[FIGCAPTION[
[19] [CITE[cURL - How To Use]]
( ([TIME[2016-05-31 06:05:05 +09:00]]))
<https://curl.haxx.se/docs/manpage.html#--unix-socket>
]FIGCAPTION]

> --unix-socket <path>
> (HTTP) Connect through this Unix domain socket, instead of using the network. (Added in 7.40.0)

]FIG]

[34] [CITE[curl - How To Use]], [TIME[2020-09-21T09:01:13.000Z]], [TIME[2020-10-01T05:40:57.414Z]] <https://curl.haxx.se/docs/manpage.html#--abstract-unix-socket>

[FIG(quote)[
[FIGCAPTION[
[21] [CITE@en[Connection String URI Format — MongoDB Manual 3.2]]
([TIME[2016-10-28 23:53:37 +09:00]])
<https://docs.mongodb.com/manual/reference/connection-string/>
]FIGCAPTION]

> The following connects to a UNIX domain socket:
> mongodb:///tmp/mongodb-27017.sock

]FIG]


[FIG(quote)[
[FIGCAPTION[
[22] [CITE@en[MySQL — SQLAlchemy 0.9 Documentation]]
([TIME[2016-11-05 07:07:26 +09:00]])
<http://docs.sqlalchemy.org/en/rel_0_9/dialects/mysql.html>
]FIGCAPTION]

> mysql+mysqldb://root@/<dbname>?unix_socket=/cloudsql/<projectid>:<instancename>

]FIG]


[FIG(quote)[
[FIGCAPTION[
[23] [CITE[java - JDBC MySQL connection using Unix Socket - Stack Overflow]]
([TIME[2016-11-17 23:47:34 +09:00]])
<http://stackoverflow.com/questions/25918416/jdbc-mysql-connection-using-unix-socket>
]FIGCAPTION]

> As another answer pointed out, it's possible (at least in Intellij IDE) to use socket connection for Mysql JDBC Connector/J (I am using version 5.1) without having to provide a socketFactory,
> jdbc:mysql://localhost:3306/database_name?socket=/tmp/mysql.sock

]FIG]


[FIG(quote)[
[FIGCAPTION[
[24] [CITE[java - JDBC MySQL connection using Unix Socket - Stack Overflow]]
([TIME[2016-11-17 23:47:57 +09:00]])
<http://stackoverflow.com/questions/25918416/jdbc-mysql-connection-using-unix-socket>
]FIGCAPTION]

> The JDBC Driver from the MariaDB project supports Unix domain sockets while remaining compatible with the MySQL Connector/J JDBC driver. Example jdbc url for the MariaDB driver is: jdbc:mariadb://localhost:3306/revmgt?localSocket=/var/run/mysqld/mysqld.sock

]FIG]


[FIG(quote)[
[FIGCAPTION[
[25] [CITE[The DB-URI — TurboGears 1.0 documentation]]
([TIME[2013-01-12 16:52:59 +09:00]])
<http://turbogears.org/1.0/docs/DbUri.html>
]FIGCAPTION]

> mysql://localhost/database?unix_socket=/var/lib/mysql/socket

]FIG]


[FIG(quote)[
[FIGCAPTION[
[26] [CITE[The DB-URI — TurboGears 1.0 documentation]]
([TIME[2013-01-12 16:52:59 +09:00]])
<http://turbogears.org/1.0/docs/DbUri.html>
]FIGCAPTION]

> If your Linux or OS X installation has a standard setup and there’s a live socket at /tmp/.s.PGSQL.5432, your SQLAlchemy PostgreSQL dburi can be this simple:
> postgres:///dbname
> To specify the socket file for PostgreSQL, put the absolute path after the double slash:
> postgres:///var/run/postgresql/test?debug=1
> However, there are bugs in the DSN parser for SQLObject, so that it fails to separate the socket path from the database name. A DSN like this works around that issue:
> postgres:///dbname?host=/path/to/socket

]FIG]


[FIG(quote)[
[FIGCAPTION[
[27] [CITE[nova.conf - configuration options - OpenStack Configuration Reference  - kilo]]
([TIME[2016-05-10 16:38:51 +09:00]])
<http://docs.openstack.org/kilo/config-reference/content/list-of-compute-config-options.html>
]FIGCAPTION]

> connection_url = None	(StrOpt) URL for connection to XenServer/Xen Cloud Platform. A special value of unix://local can be used to connect to the local unix socket. Required if compute_driver=xenapi.XenAPIDriver

]FIG]


[FIG(quote)[
[FIGCAPTION[
[28] [CITE@en[Linknx / Wiki / Services_section]]
([TIME[2016-11-18 00:10:58 +09:00]])
<https://sourceforge.net/p/linknx/wiki/Services_section/>
]FIGCAPTION]

> The knxconnection element configures the connection to EIBD. The url parameter can be "local:/path/to/unix/socket" if EIBD uses unix sockets or "ip:ip-address:port" if EIBD uses internet sockets (port is optional; default = 6720)

]FIG]



[FIG(quote)[
[FIGCAPTION[
[31] [CITE@en[Compose CLI environment variables | Docker Documentation]]
( ([TIME[2017-06-10 02:19:31 +09:00]]))
<https://docs.docker.com/compose/reference/envvars/>
]FIGCAPTION]

> DOCKER_HOST
> Sets the URL of the docker daemon. As with the Docker client, defaults to unix:///var/run/docker.sock.

]FIG]

[32] [CODE[http+docker://localunixsocket]]