@@ -535,3 +535,50 @@ func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
535535 })
536536 }
537537}
538+
539+ // Make sure that anonymous volumes can be overritten by tmpfs
540+ // https://github.com/moby/moby/issues/40446
541+ func TestCreateTmpfsOverrideAnonymousVolume (t * testing.T ) {
542+ skip .If (t , testEnv .DaemonInfo .OSType == "windows" , "windows does not support tmpfs" )
543+ defer setupTest (t )()
544+ client := testEnv .APIClient ()
545+ ctx := context .Background ()
546+
547+ id := ctr .Create (ctx , t , client ,
548+ ctr .WithVolume ("/foo" ),
549+ ctr .WithTmpfs ("/foo" ),
550+ ctr .WithVolume ("/bar" ),
551+ ctr .WithTmpfs ("/bar:size=999" ),
552+ ctr .WithCmd ("/bin/sh" , "-c" , "mount | grep '/foo' | grep tmpfs && mount | grep '/bar' | grep tmpfs" ),
553+ )
554+
555+ defer func () {
556+ err := client .ContainerRemove (ctx , id , types.ContainerRemoveOptions {Force : true })
557+ assert .NilError (t , err )
558+ }()
559+
560+ inspect , err := client .ContainerInspect (ctx , id )
561+ assert .NilError (t , err )
562+ // tmpfs do not currently get added to inspect.Mounts
563+ // Normally an anoynmous volume would, except now tmpfs should prevent that.
564+ assert .Assert (t , is .Len (inspect .Mounts , 0 ))
565+
566+ chWait , chErr := client .ContainerWait (ctx , id , container .WaitConditionNextExit )
567+ assert .NilError (t , client .ContainerStart (ctx , id , types.ContainerStartOptions {}))
568+
569+ timeout := time .NewTimer (30 * time .Second )
570+ defer timeout .Stop ()
571+
572+ select {
573+ case <- timeout .C :
574+ t .Fatal ("timeout waiting for container to exit" )
575+ case status := <- chWait :
576+ var errMsg string
577+ if status .Error != nil {
578+ errMsg = status .Error .Message
579+ }
580+ assert .Equal (t , int (status .StatusCode ), 0 , errMsg )
581+ case err := <- chErr :
582+ assert .NilError (t , err )
583+ }
584+ }
0 commit comments