Docker挂载目录Permission denied报错问题

容器目录Permission denied报错问题,笔记记录。

在一台新机器上装了docker之后,准备跑个应用测试一下,查看日志报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@test_yc ~]# docker logs -f halo
__ __ __
/ / / /___ _/ /___
/ /_/ / __ `/ / __ \
/ __ / /_/ / / /_/ /
/_/ /_/\__,_/_/\____/

::: Spring-Boot 2.1.2.RELEASE ::: Halo (version: (vlatest))
2019-03-21 10:39:22.633 INFO 1 --- [ main] cc.ryanc.halo.Application : Starting Application vlatest on 7a17a5fc4370 with PID 1 (/opt/halo/halo-latest.jar started by root in /opt/halo)
2019-03-21 10:39:22.636 INFO 1 --- [ main] cc.ryanc.halo.Application : No active profile set, falling back to default profiles: default
2019-03-21 10:39:23.220 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-03-21 10:39:23.314 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 89ms. Found 11 repository interfaces.
2019-03-21 10:39:23.615 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$79adaa2d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-21 10:39:23.862 WARN 1 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2019-03-21 10:39:23.879 INFO 1 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2019-03-21 10:39:23.880 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1214 ms
2019-03-21 10:39:24.026 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
org.h2.message.DbException: Log file error: "/root/halo/halo.trace.db", cause: "java.io.FileNotFoundException: /root/halo/halo.trace.db (Permission denied)" [90034-197]
org.h2.message.DbException: Log file error: "/root/halo/halo.trace.db", cause: "java.io.FileNotFoundException: /root/halo/halo.trace.db (Permission denied)" [90034-197]
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.TraceSystem.logWritingError(TraceSystem.java:289)
at org.h2.message.TraceSystem.openWriter(TraceSystem.java:310)
at org.h2.message.TraceSystem.writeFile(TraceSystem.java:258)
at org.h2.message.TraceSystem.write(TraceSystem.java:242)
at org.h2.message.Trace.error(Trace.java:182)
at org.h2.engine.Database.setBackgroundException(Database.java:2110)
at org.h2.mvstore.db.MVTableEngine$1.uncaughtException(MVTableEngine.java:95)
at org.h2.mvstore.MVStore.handleException(MVStore.java:2506)
at org.h2.mvstore.MVStore.panic(MVStore.java:383)
at org.h2.mvstore.MVStore.<init>(MVStore.java:364)

查阅相关资料发现,centos7中安全模块selinux把权限禁掉了,容器访问宿主机目录涉及到权限的一些问题,解决方法:关闭selinux。

1
2
3
4
5
6
#永久生效
$ sed 's@SELINUX=enforcing@SELINUX=disabled@g' /etc/selinux/config
$ reboot

#临时生效
$ setenforce 0

重新再运行一下容器,没有报错,问题解决。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

[root@test_yc ~]# docker run -d --name halo -p 8090:8090 -v /opt/halo:/root/halo -e DB_USER=root -e DB_PASSWORD=123456 ruibaby/halo
3e722be85012586b869067e58b18482555948ec4e08a5f453b67436c2128e455
[root@test_yc ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e722be85012 ruibaby/halo "java -Djava.secur..." 5 seconds ago Up 3 seconds 0.0.0.0:8090->8090/tcp halo
[root@test_yc ~]# docker logs -f halo
__ __ __
/ / / /___ _/ /___
/ /_/ / __ `/ / __ \
/ __ / /_/ / / /_/ /
/_/ /_/\__,_/_/\____/

::: Spring-Boot 2.1.2.RELEASE ::: Halo (version: (vlatest))
2019-03-21 10:45:35.741 INFO 1 --- [ main] cc.ryanc.halo.Application : Starting Application vlatest on 3e722be85012 with PID 1 (/opt/halo/halo-latest.jar started by root in /opt/halo)
2019-03-21 10:45:35.744 INFO 1 --- [ main] cc.ryanc.halo.Application : No active profile set, falling back to default profiles: default
2019-03-21 10:45:36.346 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-03-21 10:45:36.434 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 82ms. Found 11 repository interfaces.
2019-03-21 10:45:36.768 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$8585e1ec] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-21 10:45:37.015 WARN 1 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2019-03-21 10:45:37.032 INFO 1 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2019-03-21 10:45:37.032 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1252 ms
2019-03-21 10:45:37.189 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-03-21 10:45:37.423 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-03-21 10:45:37.488 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-03-21 10:45:37.543 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
2019-03-21 10:45:37.545 INFO 1 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-03-21 10:45:37.673 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-03-21 10:45:37.796 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-03-21 10:45:38.532 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-03-21 10:45:39.347 INFO 1 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2019-03-21 10:45:39.480 WARN 1 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-03-21 10:45:39.903 INFO 1 --- [ main] org.xnio : XNIO version 3.3.8.Final
2019-03-21 10:45:39.910 INFO 1 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2019-03-21 10:45:39.988 INFO 1 --- [ main] o.s.b.w.e.u.UndertowServletWebServer : Undertow started on port(s) 8090 (http) with context path ''
2019-03-21 10:45:39.990 INFO 1 --- [ main] cc.ryanc.halo.Application : Started Application in 4.606 seconds (JVM running for 5.964)
2019-03-21 10:45:40.077 INFO 1 --- [ main] cc.ryanc.halo.listener.StartedListener : The scheduled task starts successfully!
2019-03-21 10:45:40.079 INFO 1 --- [ main] cc.ryanc.halo.Application : Halo started at http://localhost:8090
2019-03-21 11:00:00.005 INFO 1 --- [ hutool-cron-1] cc.ryanc.halo.task.PostSyncTask : The number of visits to 0 posts has been updated
-------------本文结束感谢您的阅读-------------